├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .postcssrc.js ├── README.md ├── build ├── build-nw.js ├── build-upgrade.js ├── build-win-setup.js ├── build.js ├── check-versions.js ├── dev-client.js ├── dev-nw.js ├── dev-server.js ├── setup_resources │ ├── ChineseSimp.isl │ ├── license.txt │ ├── logo.icns │ └── logo.ico ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.dev.conf.js └── webpack.prod.conf.js ├── config ├── dev.env.js ├── index.js ├── prod.env.js └── setup.iss ├── docs ├── README_ZH.md └── assets │ ├── build.gif │ ├── dev.gif │ ├── upgrade.gif │ └── win-setup.gif ├── index.html ├── package.json ├── src ├── App.vue ├── components │ ├── Hello.vue │ └── Update.vue ├── main.js ├── router │ └── index.js └── utils │ └── update.js └── static ├── .gitkeep └── logo.png /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { "modules": false }], 4 | "stage-2" 5 | ], 6 | "plugins": ["transform-runtime"], 7 | "comments": false, 8 | "env": { 9 | "test": { 10 | "presets": ["env", "stage-2"], 11 | "plugins": [ "istanbul" ] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | build/*.js 2 | config/*.js 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // http://eslint.org/docs/user-guide/configuring 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | sourceType: 'module' 8 | }, 9 | env: { 10 | browser: true, 11 | }, 12 | // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style 13 | extends: 'standard', 14 | // required to lint *.vue files 15 | plugins: [ 16 | 'html' 17 | ], 18 | // add your custom rules here 19 | 'rules': { 20 | // allow paren-less arrow functions 21 | 'arrow-parens': 0, 22 | // allow async-await 23 | 'generator-star-spacing': 0, 24 | // allow debugger during development 25 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | output/ 5 | releases/ 6 | npm-debug.log 7 | yarn-error.log 8 | -------------------------------------------------------------------------------- /.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | // to edit target browsers: use "browserlist" field in package.json 6 | "autoprefixer": {} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-nw-seed 2 | 3 | > A seed project with Vue.js and Nw.js 4 | 5 | [english](/README.md) | [中文](/docs/README_ZH.md) 6 | 7 | ## Build Setup 8 | 9 | ``` bash 10 | # install dependencies 11 | npm install 12 | 13 | # serve with hot reload at localhost:8080 14 | npm run dev 15 | 16 | # build for production with minification 17 | npm run build 18 | 19 | # build for production and view the bundle analyzer report 20 | npm run build --report 21 | 22 | # only build nw 23 | npm run build --onlyNW 24 | 25 | # default is build `setup.exe` in windows 26 | npm run build --noSetup 27 | ``` 28 | 29 | For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). 30 | 31 | ## Demo 32 | ### `npm run dev` 33 |  34 | 35 | ### `npm run build` 36 |  37 | 38 | ### `for upgrade` 39 |  40 | 41 | ### Build a beautiful setup for windows 42 | This feature in [vue-nw-seed/origin/win-beautiful-setup](https://github.com/anchengjian/vue-nw-seed/tree/win-beautiful-setup) branch. 43 |  44 | 45 | ## FAQ 46 | ### Why nw@0.14.7 ? 47 | Not all of NW.js support `XP`, because from the beginning of `Chromium50` does not support the XP, so if your client want to support XP, the best of version is `0.14.7`. See NW.js's blog: [NW.js v0.14.7 (LTS) Released](https://nwjs.io/blog/v0.14.7/) 48 | -------------------------------------------------------------------------------- /build/build-nw.js: -------------------------------------------------------------------------------- 1 | var exec = require('child_process').exec 2 | var path = require('path') 3 | var fs = require('fs') 4 | var util = require('util') 5 | 6 | var buildWinSetup = require('./build-win-setup.js') 7 | var buildUpgrade = require('./build-upgrade') 8 | 9 | var rootPath = path.resolve(__dirname, '../') 10 | 11 | // get config 12 | var config = require(path.resolve(rootPath, 'config')) 13 | 14 | // `./package.json` 15 | var tmpJson = require(path.resolve(rootPath, './package.json')) 16 | var manifestPath = path.resolve(config.build.assetsRoot, './package.json') 17 | 18 | // manifest for `./dist/package.json` 19 | var manifest = {} 20 | config.build.nw.manifest.forEach(function(v, i) { 21 | if (util.isString(v)) manifest[v] = tmpJson[v] 22 | else if (util.isObject(v)) manifest = util._extend(manifest, v) 23 | }) 24 | 25 | fs.writeFile(manifestPath, JSON.stringify(manifest, null, ' '), 'utf-8', function(err) { 26 | if (err) throw err 27 | 28 | // start build app 29 | if (!config.build.nw.builder) return 30 | var NwBuilder = require('nw-builder') 31 | var nw = new NwBuilder(config.build.nw.builder) 32 | nw.build(function(err, data) { 33 | if (err) console.log(err) 34 | console.log('build nw done!') 35 | 36 | // build windows setup 37 | if (config.build.noSetup) return 38 | if (~config.build.nw.builder.platforms.toString().indexOf('win')) buildWinSetup().then(() => buildUpgrade(manifest)) 39 | else buildUpgrade(manifest) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /build/build-upgrade.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var fs = require('fs') 3 | 4 | var rootPath = path.resolve(__dirname, '../') 5 | 6 | // get config 7 | var config = require(path.resolve(rootPath, 'config')) 8 | var setupCnf = config.build.nw.setup 9 | var updCnf = config.build.nw.upgrade 10 | 11 | // var platforms = ['win32', 'win64', 'osx32', 'osx64', 'linux32', 'linux64'] 12 | var platforms = { 13 | 'win32-setup': { 14 | name: 'win32', 15 | ext: '.exe' 16 | }, 17 | 'win64-setup': { 18 | name: 'win64', 19 | ext: '.exe' 20 | }, 21 | 'osx32': { 22 | name: 'osx32', 23 | ext: '.app' 24 | }, 25 | 'osx64': { 26 | name: 'osx64', 27 | ext: '.app' 28 | }, 29 | 'linux32': { 30 | name: 'linux32', 31 | ext: '.gz' 32 | }, 33 | 'linux64': { 34 | name: 'linux64', 35 | ext: '.gz' 36 | } 37 | } 38 | 39 | // `./output/pc.json` 40 | module.exports = makeUpgrade 41 | 42 | // makeUpgrade({ name: 'vue-nw-seed', appName: '应用的中文别名', version: '0.1.0' }) 43 | function makeUpgrade(manifest) { 44 | var upgradeJson = Object.assign({}, manifest, { packages: {} }) 45 | 46 | // due to files 47 | updCnf.files.forEach(function (curPath) { 48 | var files = fs.readdirSync(curPath) 49 | 50 | files.forEach(function (fileName) { 51 | var platform = platforms[fileName] 52 | if (!platform) return 53 | 54 | var filePath = getFilePath(manifest, platform, fileName) 55 | var size = getFileSize(curPath, manifest, platform, fileName) 56 | upgradeJson.packages[platform.name] = { url: updCnf.publicPath + filePath, size: size } 57 | }) 58 | makeJson(upgradeJson) 59 | }) 60 | } 61 | 62 | function getFilePath(manifest, platform, fileName) { 63 | var file = getFile(manifest, platform, fileName) 64 | return manifest.version + '/' + file 65 | } 66 | 67 | function getFileSize(curPath, manifest, platform, fileName) { 68 | var file = getFile(manifest, platform, fileName) 69 | return fs.statSync(path.resolve(curPath, file)).size 70 | } 71 | 72 | function getFile(manifest, platform, fileName) { 73 | var name = manifest.name 74 | if (typeof setupCnf.outputFileName === 'function') { 75 | name = setupCnf.outputFileName({ name: manifest.name, version: manifest.version, platform }) 76 | } 77 | return fileName + '/' + name + platform.ext 78 | } 79 | 80 | function makeJson(json) { 81 | var upgradeAssetsRoot = path.parse(updCnf.outputFile).dir 82 | if (!fs.existsSync(upgradeAssetsRoot)) fs.mkdirSync(upgradeAssetsRoot) 83 | 84 | fs.writeFile(updCnf.outputFile, JSON.stringify(json, null, ' '), 'utf-8', function (err) { 85 | if (err) console.log(err) 86 | console.log('\n', 'build upgrade.json in:\n', updCnf.outputFile, '\n') 87 | }) 88 | } 89 | -------------------------------------------------------------------------------- /build/build-win-setup.js: -------------------------------------------------------------------------------- 1 | var innosetupCompiler = require('innosetup-compiler') 2 | var path = require('path') 3 | var fs = require('fs') 4 | var iconv = require('iconv-lite') 5 | 6 | var rootPath = path.resolve(__dirname, '../') 7 | 8 | // `./package.json` 9 | var tmpJson = require(path.resolve(rootPath, './package.json')) 10 | 11 | // get config 12 | var config = require(path.resolve(rootPath, 'config')) 13 | var setupOptions = config.build.nw.setup 14 | var platforms = ['win32', 'win64'] 15 | 16 | module.exports = function () { 17 | const res = [] 18 | const files = fs.readdirSync(setupOptions.files) 19 | 20 | files.forEach(function (fileName) { 21 | if (!~platforms.indexOf(fileName)) return 22 | 23 | const curPath = path.resolve(setupOptions.files, fileName) 24 | const stats = fs.statSync(curPath) 25 | if (!stats.isDirectory()) return 26 | 27 | const options = Object.assign({}, setupOptions, { files: curPath, platform: fileName }) 28 | options.outputPath = options.outputPath || path.resolve(setupOptions.files, fileName + '-setup') 29 | 30 | res.push(makeExeSetup(options)) 31 | }) 32 | 33 | return Promise.all(res) 34 | } 35 | 36 | function makeExeSetup(opt) { 37 | const { issPath, files, outputPath, outputFileName, resourcesPath, appPublisher, appURL, appId, platform } = opt 38 | const { name, appName, version } = tmpJson 39 | const tmpIssPath = path.resolve(path.parse(issPath).dir, '_tmp_' + platform + '.iss') 40 | const getOutputNameHandle = typeof outputFileName === 'function' ? outputFileName : getOutputName 41 | 42 | return new Promise(function (resolve, reject) { 43 | // rewrite name, version to iss 44 | fs.readFile(issPath, null, function (err, text) { 45 | if (err) return reject(err) 46 | 47 | let str = iconv.decode(text, 'gbk') 48 | .replace(/_name_/g, name) 49 | .replace(/_appName_/g, appName) 50 | .replace(/_version_/g, version) 51 | .replace(/_outputPath_/g, outputPath) 52 | .replace(/_outputFileName_/g, getOutputNameHandle({ name, version, platform })) 53 | .replace(/_filesPath_/g, files) 54 | .replace(/_resourcesPath_/g, resourcesPath) 55 | .replace(/_appPublisher_/g, appPublisher) 56 | .replace(/_appURL_/g, appURL) 57 | .replace(/_appId_/g, appId) 58 | .replace(/_platform_/g, platform === 'win64' ? '64' : '') 59 | 60 | fs.writeFile(tmpIssPath, iconv.encode(str, 'gbk'), null, function (err) { 61 | if (err) return reject(err) 62 | 63 | // inno setup start 64 | innosetupCompiler(tmpIssPath, { gui: false, verbose: true }, function (err) { 65 | fs.unlinkSync(tmpIssPath) 66 | if (err) return reject(err) 67 | resolve(opt) 68 | }) 69 | }) 70 | }) 71 | }) 72 | } 73 | 74 | function getOutputName(data) { 75 | return data.name 76 | } 77 | -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | process.env.NODE_ENV = 'production' 4 | 5 | var ora = require('ora') 6 | var rm = require('rimraf') 7 | var path = require('path') 8 | var chalk = require('chalk') 9 | var webpack = require('webpack') 10 | var config = require('../config') 11 | var webpackConfig = require('./webpack.prod.conf') 12 | 13 | if (config.build.onlyNW) return require('./build-nw.js') 14 | 15 | var spinner = ora('building for production...') 16 | spinner.start() 17 | 18 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 19 | if (err) throw err 20 | webpack(webpackConfig, function(err, stats) { 21 | spinner.stop() 22 | if (err) throw err 23 | process.stdout.write(stats.toString({ 24 | colors: true, 25 | modules: false, 26 | children: false, 27 | chunks: false, 28 | chunkModules: false 29 | }) + '\n\n') 30 | 31 | console.log(chalk.cyan(' Build complete.\n')) 32 | console.log(chalk.yellow( 33 | ' Tip: built files are meant to be served over an HTTP server.\n' + 34 | ' Opening index.html over file:// won\'t work.\n' 35 | )) 36 | 37 | // start build nw.js app 38 | require('./build-nw.js') 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /build/check-versions.js: -------------------------------------------------------------------------------- 1 | var chalk = require('chalk') 2 | var semver = require('semver') 3 | var packageConfig = require('../package.json') 4 | 5 | function exec (cmd) { 6 | return require('child_process').execSync(cmd).toString().trim() 7 | } 8 | 9 | var versionRequirements = [ 10 | { 11 | name: 'node', 12 | currentVersion: semver.clean(process.version), 13 | versionRequirement: packageConfig.engines.node 14 | }, 15 | { 16 | name: 'npm', 17 | currentVersion: exec('npm --version'), 18 | versionRequirement: packageConfig.engines.npm 19 | } 20 | ] 21 | 22 | module.exports = function () { 23 | var warnings = [] 24 | for (var i = 0; i < versionRequirements.length; i++) { 25 | var mod = versionRequirements[i] 26 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 27 | warnings.push(mod.name + ': ' + 28 | chalk.red(mod.currentVersion) + ' should be ' + 29 | chalk.green(mod.versionRequirement) 30 | ) 31 | } 32 | } 33 | 34 | if (warnings.length) { 35 | console.log('') 36 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 37 | console.log() 38 | for (var i = 0; i < warnings.length; i++) { 39 | var warning = warnings[i] 40 | console.log(' ' + warning) 41 | } 42 | console.log() 43 | process.exit(1) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /build/dev-client.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | require('eventsource-polyfill') 3 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') 4 | 5 | hotClient.subscribe(function (event) { 6 | if (event.action === 'reload') { 7 | window.location.reload() 8 | } 9 | }) 10 | -------------------------------------------------------------------------------- /build/dev-nw.js: -------------------------------------------------------------------------------- 1 | var exec = require('child_process').exec 2 | var path = require('path') 3 | var fs = require('fs') 4 | var nwPath = require('nw').findpath() 5 | var rootPath = path.resolve(__dirname, '../') 6 | var packageJsonPath = path.resolve(rootPath, './package.json') 7 | 8 | module.exports = runNwDev 9 | 10 | function runNwDev(uri = '') { 11 | if (uri && (uri + '').trim()) { 12 | tmpJson = require(packageJsonPath) 13 | tmpJson.main = uri 14 | fs.writeFileSync(packageJsonPath, JSON.stringify(tmpJson, null, ' '), 'utf-8') 15 | } 16 | 17 | var closed 18 | var nwDev = exec(nwPath + ' ' + rootPath, { cwd: rootPath }, function(err, stdout, stderr) { 19 | process.exit(0) 20 | closed = true 21 | }) 22 | 23 | nwDev.stdout.on('data', console.log) 24 | nwDev.stdout.on('error', console.error) 25 | 26 | // 退出时也关闭 NW 进程 27 | process.on('exit', exitHandle) 28 | process.on('uncaughtException', exitHandle) 29 | 30 | function exitHandle(e) { 31 | if (!closed) nwDev.kill() 32 | console.log(e || '233333, bye~~~') 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /build/dev-server.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | var config = require('../config') 4 | if (!process.env.NODE_ENV) { 5 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) 6 | } 7 | 8 | var path = require('path') 9 | var express = require('express') 10 | var webpack = require('webpack') 11 | var proxyMiddleware = require('http-proxy-middleware') 12 | var webpackConfig = require('./webpack.dev.conf') 13 | 14 | // default port where dev server listens for incoming traffic 15 | var port = process.env.PORT || config.dev.port 16 | // automatically open browser, if not set will be false 17 | var autoOpenBrowser = !!config.dev.autoOpenBrowser 18 | // Define HTTP proxies to your custom API backend 19 | // https://github.com/chimurai/http-proxy-middleware 20 | var proxyTable = config.dev.proxyTable 21 | 22 | var app = express() 23 | var compiler = webpack(webpackConfig) 24 | 25 | var devMiddleware = require('webpack-dev-middleware')(compiler, { 26 | publicPath: webpackConfig.output.publicPath, 27 | quiet: true 28 | }) 29 | 30 | var hotMiddleware = require('webpack-hot-middleware')(compiler, { 31 | log: () => {} 32 | }) 33 | // force page reload when html-webpack-plugin template changes 34 | compiler.plugin('compilation', function(compilation) { 35 | compilation.plugin('html-webpack-plugin-after-emit', function(data, cb) { 36 | hotMiddleware.publish({ action: 'reload' }) 37 | cb() 38 | }) 39 | }) 40 | 41 | // proxy api requests 42 | Object.keys(proxyTable).forEach(function(context) { 43 | var options = proxyTable[context] 44 | if (typeof options === 'string') { 45 | options = { target: options } 46 | } 47 | app.use(proxyMiddleware(options.filter || context, options)) 48 | }) 49 | 50 | // handle fallback for HTML5 history API 51 | app.use(require('connect-history-api-fallback')()) 52 | 53 | // serve webpack bundle output 54 | app.use(devMiddleware) 55 | 56 | // enable hot-reload and state-preserving 57 | // compilation error display 58 | app.use(hotMiddleware) 59 | 60 | // serve pure static assets 61 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 62 | app.use(staticPath, express.static('./static')) 63 | 64 | // for upgrade server 65 | var upgrade = config.dev.upgrade 66 | if (upgrade && upgrade.publicPath && upgrade.directory) { 67 | app.use(upgrade.publicPath, [function(req, res, next) { 68 | console.log(req.url, JSON.stringify(req.headers)) 69 | next() 70 | }, express.static(upgrade.directory)]) 71 | } 72 | 73 | var uri = 'http://localhost:' + port 74 | 75 | devMiddleware.waitUntilValid(function() { 76 | console.log('> Listening at ' + uri + '\n') 77 | }) 78 | 79 | module.exports = app.listen(port, function(err) { 80 | if (err) { 81 | console.log(err) 82 | return 83 | } 84 | 85 | // when env is testing, don't need open it 86 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { 87 | require('./dev-nw')(uri) 88 | } 89 | }) 90 | -------------------------------------------------------------------------------- /build/setup_resources/ChineseSimp.isl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anchengjian/vue-nw-seed/3cb859131540bf05a26f5c54a64d716442e178ee/build/setup_resources/ChineseSimp.isl -------------------------------------------------------------------------------- /build/setup_resources/license.txt: -------------------------------------------------------------------------------- 1 | welcome vue-nw-seed. 2 | 3 | 2333 4 | 5 | +1s 6 | -------------------------------------------------------------------------------- /build/setup_resources/logo.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anchengjian/vue-nw-seed/3cb859131540bf05a26f5c54a64d716442e178ee/build/setup_resources/logo.icns -------------------------------------------------------------------------------- /build/setup_resources/logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anchengjian/vue-nw-seed/3cb859131540bf05a26f5c54a64d716442e178ee/build/setup_resources/logo.ico -------------------------------------------------------------------------------- /build/utils.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var config = require('../config') 3 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 4 | 5 | exports.assetsPath = function (_path) { 6 | var assetsSubDirectory = process.env.NODE_ENV === 'production' 7 | ? config.build.assetsSubDirectory 8 | : config.dev.assetsSubDirectory 9 | return path.posix.join(assetsSubDirectory, _path) 10 | } 11 | 12 | exports.cssLoaders = function (options) { 13 | options = options || {} 14 | 15 | var cssLoader = { 16 | loader: 'css-loader', 17 | options: { 18 | minimize: process.env.NODE_ENV === 'production', 19 | sourceMap: options.sourceMap 20 | } 21 | } 22 | 23 | // generate loader string to be used with extract text plugin 24 | function generateLoaders (loader, loaderOptions) { 25 | var loaders = [cssLoader] 26 | if (loader) { 27 | loaders.push({ 28 | loader: loader + '-loader', 29 | options: Object.assign({}, loaderOptions, { 30 | sourceMap: options.sourceMap 31 | }) 32 | }) 33 | } 34 | 35 | // Extract CSS when that option is specified 36 | // (which is the case during production build) 37 | if (options.extract) { 38 | return ExtractTextPlugin.extract({ 39 | use: loaders, 40 | fallback: 'vue-style-loader' 41 | }) 42 | } else { 43 | return ['vue-style-loader'].concat(loaders) 44 | } 45 | } 46 | 47 | // http://vuejs.github.io/vue-loader/en/configurations/extract-css.html 48 | return { 49 | css: generateLoaders(), 50 | postcss: generateLoaders(), 51 | less: generateLoaders('less'), 52 | sass: generateLoaders('sass', { indentedSyntax: true }), 53 | scss: generateLoaders('sass'), 54 | stylus: generateLoaders('stylus'), 55 | styl: generateLoaders('stylus') 56 | } 57 | } 58 | 59 | // Generate loaders for standalone style files (outside of .vue) 60 | exports.styleLoaders = function (options) { 61 | var output = [] 62 | var loaders = exports.cssLoaders(options) 63 | for (var extension in loaders) { 64 | var loader = loaders[extension] 65 | output.push({ 66 | test: new RegExp('\\.' + extension + '$'), 67 | use: loader 68 | }) 69 | } 70 | return output 71 | } 72 | -------------------------------------------------------------------------------- /build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var config = require('../config') 3 | var isProduction = process.env.NODE_ENV === 'production' 4 | 5 | module.exports = { 6 | loaders: utils.cssLoaders({ 7 | sourceMap: isProduction 8 | ? config.build.productionSourceMap 9 | : config.dev.cssSourceMap, 10 | extract: isProduction 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var config = require('../config') 4 | var vueLoaderConfig = require('./vue-loader.conf') 5 | 6 | function resolve (dir) { 7 | return path.join(__dirname, '..', dir) 8 | } 9 | 10 | module.exports = { 11 | entry: { 12 | app: './src/main.js' 13 | }, 14 | output: { 15 | path: config.build.assetsRoot, 16 | filename: '[name].js', 17 | publicPath: process.env.NODE_ENV === 'production' 18 | ? config.build.assetsPublicPath 19 | : config.dev.assetsPublicPath 20 | }, 21 | resolve: { 22 | extensions: ['.js', '.vue', '.json'], 23 | alias: { 24 | 'vue$': 'vue/dist/vue.esm.js', 25 | '@': resolve('src'), 26 | } 27 | }, 28 | module: { 29 | rules: [ 30 | { 31 | test: /\.(js|vue)$/, 32 | loader: 'eslint-loader', 33 | enforce: "pre", 34 | include: [resolve('src'), resolve('test')], 35 | options: { 36 | formatter: require('eslint-friendly-formatter') 37 | } 38 | }, 39 | { 40 | test: /\.vue$/, 41 | loader: 'vue-loader', 42 | options: vueLoaderConfig 43 | }, 44 | { 45 | test: /\.js$/, 46 | loader: 'babel-loader', 47 | include: [resolve('src'), resolve('test')] 48 | }, 49 | { 50 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 51 | loader: 'url-loader', 52 | query: { 53 | limit: 10000, 54 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 55 | } 56 | }, 57 | { 58 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 59 | loader: 'url-loader', 60 | query: { 61 | limit: 10000, 62 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 63 | } 64 | } 65 | ] 66 | }, 67 | target: 'node-webkit' 68 | } 69 | -------------------------------------------------------------------------------- /build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var webpack = require('webpack') 3 | var config = require('../config') 4 | var merge = require('webpack-merge') 5 | var baseWebpackConfig = require('./webpack.base.conf') 6 | var HtmlWebpackPlugin = require('html-webpack-plugin') 7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 8 | 9 | // add hot-reload related code to entry chunks 10 | Object.keys(baseWebpackConfig.entry).forEach(function (name) { 11 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) 12 | }) 13 | 14 | module.exports = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) 17 | }, 18 | // cheap-module-eval-source-map is faster for development 19 | devtool: '#cheap-module-eval-source-map', 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | 'process.env': config.dev.env 23 | }), 24 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage 25 | new webpack.HotModuleReplacementPlugin(), 26 | new webpack.NoEmitOnErrorsPlugin(), 27 | // https://github.com/ampedandwired/html-webpack-plugin 28 | new HtmlWebpackPlugin({ 29 | filename: 'index.html', 30 | template: 'index.html', 31 | inject: true 32 | }), 33 | new FriendlyErrorsPlugin() 34 | ] 35 | }) 36 | -------------------------------------------------------------------------------- /build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var webpack = require('webpack') 4 | var config = require('../config') 5 | var merge = require('webpack-merge') 6 | var baseWebpackConfig = require('./webpack.base.conf') 7 | var CopyWebpackPlugin = require('copy-webpack-plugin') 8 | var HtmlWebpackPlugin = require('html-webpack-plugin') 9 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 11 | 12 | var env = config.build.env 13 | 14 | var webpackConfig = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ 17 | sourceMap: config.build.productionSourceMap, 18 | extract: true 19 | }) 20 | }, 21 | devtool: config.build.productionSourceMap ? '#source-map' : false, 22 | output: { 23 | path: config.build.assetsRoot, 24 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 25 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 26 | }, 27 | plugins: [ 28 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 29 | new webpack.DefinePlugin({ 30 | 'process.env': env 31 | }), 32 | new webpack.optimize.UglifyJsPlugin({ 33 | compress: { 34 | warnings: false 35 | }, 36 | sourceMap: true 37 | }), 38 | // extract css into its own file 39 | new ExtractTextPlugin({ 40 | filename: utils.assetsPath('css/[name].[contenthash].css') 41 | }), 42 | // Compress extracted CSS. We are using this plugin so that possible 43 | // duplicated CSS from different components can be deduped. 44 | new OptimizeCSSPlugin(), 45 | // generate dist index.html with correct asset hash for caching. 46 | // you can customize output by editing /index.html 47 | // see https://github.com/ampedandwired/html-webpack-plugin 48 | new HtmlWebpackPlugin({ 49 | filename: config.build.index, 50 | template: 'index.html', 51 | inject: true, 52 | minify: { 53 | removeComments: true, 54 | collapseWhitespace: true, 55 | removeAttributeQuotes: true 56 | // more options: 57 | // https://github.com/kangax/html-minifier#options-quick-reference 58 | }, 59 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 60 | chunksSortMode: 'dependency' 61 | }), 62 | // split vendor js into its own file 63 | new webpack.optimize.CommonsChunkPlugin({ 64 | name: 'vendor', 65 | minChunks: function (module, count) { 66 | // any required modules inside node_modules are extracted to vendor 67 | return ( 68 | module.resource && 69 | /\.js$/.test(module.resource) && 70 | module.resource.indexOf( 71 | path.join(__dirname, '../node_modules') 72 | ) === 0 73 | ) 74 | } 75 | }), 76 | // extract webpack runtime and module manifest to its own file in order to 77 | // prevent vendor hash from being updated whenever app bundle is updated 78 | new webpack.optimize.CommonsChunkPlugin({ 79 | name: 'manifest', 80 | chunks: ['vendor'] 81 | }), 82 | // copy custom static assets 83 | new CopyWebpackPlugin([ 84 | { 85 | from: path.resolve(__dirname, '../static'), 86 | to: config.build.assetsSubDirectory, 87 | ignore: ['.*'] 88 | } 89 | ]) 90 | ] 91 | }) 92 | 93 | if (config.build.productionGzip) { 94 | var CompressionWebpackPlugin = require('compression-webpack-plugin') 95 | 96 | webpackConfig.plugins.push( 97 | new CompressionWebpackPlugin({ 98 | asset: '[path].gz[query]', 99 | algorithm: 'gzip', 100 | test: new RegExp( 101 | '\\.(' + 102 | config.build.productionGzipExtensions.join('|') + 103 | ')$' 104 | ), 105 | threshold: 10240, 106 | minRatio: 0.8 107 | }) 108 | ) 109 | } 110 | 111 | if (config.build.bundleAnalyzerReport) { 112 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 113 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 114 | } 115 | 116 | module.exports = webpackConfig 117 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | function resolve() { 5 | return path.resolve.apply(path, [__dirname, '..'].concat(...arguments)) 6 | } 7 | 8 | // `./package.json` 9 | var tmpJson = require(resolve('./package.json')) 10 | 11 | // var curReleasesPath = resolve('./releases', tmpJson.name + '-v' + tmpJson.version) 12 | var curReleasesPath = resolve('./releases', tmpJson.version) 13 | 14 | module.exports = { 15 | build: { 16 | env: require('./prod.env'), 17 | index: resolve('./dist/index.html'), 18 | assetsRoot: resolve('./dist'), 19 | assetsSubDirectory: 'static', 20 | assetsPublicPath: '/', 21 | productionSourceMap: false, 22 | // Gzip off by default as many popular static hosts such as 23 | // Surge or Netlify already gzip all static assets for you. 24 | // Before setting to `true`, make sure to: 25 | // npm install --save-dev compression-webpack-plugin 26 | productionGzip: false, 27 | productionGzipExtensions: ['js', 'css'], 28 | // Run the build command with an extra argument to 29 | // View the bundle analyzer report after build finishes: 30 | // `npm run build --report` 31 | // Set to `true` or `false` to always turn it on or off 32 | bundleAnalyzerReport: process.env.npm_config_report, 33 | // only build nw 34 | onlyNW: process.env.npm_config_onlyNW, 35 | // only build nw 36 | noSetup: process.env.npm_config_noSetup, 37 | nw: { 38 | // manifest for nw 39 | // the fileds will merge with `./package.json` and build to `./dist/package.json` for NW.js 40 | // Manifest Format: http://docs.nwjs.io/en/latest/References/Manifest%20Format/ 41 | manifest: ['name', 'appName', 'version', 'description', 'author', { main: './index.html' }, 'manifestUrl', 'window', 'nodejs', 'js-flags', 'node-remote'], 42 | // see document: https://github.com/nwjs/nw-builder 43 | builder: { 44 | files: [resolve('./dist/**')], 45 | // platforms: ['win32', 'win64', 'osx64'], 46 | platforms: ['win32', 'win64'], 47 | version: '0.14.7', 48 | flavor: 'normal', 49 | cacheDir: resolve('./node_modules/_nw-builder-cache/'), 50 | buildDir: resolve('./releases'), 51 | winIco: resolve('./build/setup_resources/logo.ico'), 52 | macIcns: resolve('./build/setup_resources/logo.icns'), 53 | buildType: function () { 54 | return this.appVersion 55 | } 56 | }, 57 | setup: { 58 | issPath: resolve('./config/setup.iss'), 59 | // only one version path 60 | files: curReleasesPath, 61 | resourcesPath: resolve('./build/setup_resources'), 62 | appPublisher: 'vue-nw-seed, Inc.', 63 | appURL: 'https://github.com/anchengjian/vue-nw-seed', 64 | appId: '{{A448363D-3A2F-4800-B62D-8A1C4D8F1115}}', 65 | // data: { name, version, platform } 66 | outputFileName: function (data) { 67 | return data.name + '-' + data.version 68 | } 69 | }, 70 | upgrade: { 71 | outputFile: resolve('./releases/upgrade.json'), 72 | publicPath: 'http://localhost:8080/releases/', 73 | files: [curReleasesPath] 74 | } 75 | } 76 | }, 77 | dev: { 78 | env: require('./dev.env'), 79 | port: 8080, 80 | autoOpenBrowser: true, 81 | assetsSubDirectory: 'static', 82 | assetsPublicPath: '/', 83 | proxyTable: {}, 84 | // CSS Sourcemaps off by default because relative paths are "buggy" 85 | // with this option, according to the CSS-Loader README 86 | // (https://github.com/webpack/css-loader#sourcemaps) 87 | // In our experience, they generally work as expected, 88 | // just be aware of this issue when enabling this option. 89 | cssSourceMap: false, 90 | upgrade: { 91 | publicPath: '/releases', 92 | directory: 'releases' 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /config/setup.iss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anchengjian/vue-nw-seed/3cb859131540bf05a26f5c54a64d716442e178ee/config/setup.iss -------------------------------------------------------------------------------- /docs/README_ZH.md: -------------------------------------------------------------------------------- 1 | # vue-nw-seed 2 | 3 | > 一个 Vue.js 和 Nw.js 的种子项目 4 | 5 | [english](/README.md) | [中文](/docs/README_ZH.md) 6 | 7 | ## Build Setup 8 | 9 | ``` bash 10 | # install dependencies 11 | npm install 12 | 13 | # serve with hot reload at localhost:8080 14 | npm run dev 15 | 16 | # build for production with minification 17 | npm run build 18 | 19 | # build for production and view the bundle analyzer report 20 | npm run build --report 21 | 22 | # 有了 `dist` 的情况下,仅仅打包 NW 23 | npm run build --onlyNW 24 | 25 | # windows 下不打包 setup 文件 26 | npm run build --noSetup 27 | ``` 28 | 29 | For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). 30 | 31 | ## Demo 32 | ### `npm run dev` 33 |  34 | 35 | ### `npm run build` 36 |  37 | 38 | ### 升级更新 39 |  40 | 41 | ### 制作一个更漂亮的 windows 安装程序 42 | 这个功能目前在 [vue-nw-seed/origin/win-beautiful-setup](https://github.com/anchengjian/vue-nw-seed/tree/win-beautiful-setup) 分支上。 43 |  44 | 45 | ## 常见问答 46 | ### 为啥要固定 nw 版本为 0.14.7 ? 47 | NW.js 不是全版本都支持 XP,由于 Chromium50 开始就不支持XP了,所以如果你的客户端要支持 XP,目前最佳的版本选择是 `0.14.7` 。参见 NW.js 的博客 [NW.js v0.14.7 (LTS) Released](https://nwjs.io/blog/v0.14.7/) 48 | ### 国内用 NPM 安装 NW 很慢很卡! 49 | 可以先想办法把包体下下来到本地,再进行安装。在我之前的一篇文章中介绍过: [用 vue2 和 webpack 快速建构 NW.js 项目](https://github.com/anchengjian/anchengjian.github.io/blob/master/posts/2017/vuejs-webpack-nwjs.md) 50 | 51 | ### 安装包默认是英文? 52 | 如果您不做任何更改,则默认是英文的。 53 | 汉化的话,我提供了一个中文语言包。请手动打开 `./config/setup.iss` 中关于 `Languages` 的注释。 -------------------------------------------------------------------------------- /docs/assets/build.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anchengjian/vue-nw-seed/3cb859131540bf05a26f5c54a64d716442e178ee/docs/assets/build.gif -------------------------------------------------------------------------------- /docs/assets/dev.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anchengjian/vue-nw-seed/3cb859131540bf05a26f5c54a64d716442e178ee/docs/assets/dev.gif -------------------------------------------------------------------------------- /docs/assets/upgrade.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anchengjian/vue-nw-seed/3cb859131540bf05a26f5c54a64d716442e178ee/docs/assets/upgrade.gif -------------------------------------------------------------------------------- /docs/assets/win-setup.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anchengjian/vue-nw-seed/3cb859131540bf05a26f5c54a64d716442e178ee/docs/assets/win-setup.gif -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |No update
6 |download error
13 |Download: {{progress}} %
14 |