From dcb5abf3e7fbb5481b14a6509d468b84c1744067 Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Mon, 6 Feb 2017 00:18:24 +0800 Subject: [PATCH 1/5] add hmrEntries --- bin/vue-build | 32 ++++++++++++++++++++++---------- docs/build.md | 9 ++++++++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/bin/vue-build b/bin/vue-build index 6dbc799da5..6a1e369a81 100755 --- a/bin/vue-build +++ b/bin/vue-build @@ -81,7 +81,7 @@ var options = merge({ }) function help () { - if (!options.run && !options.entry) { + if (!options.config && !options.entry) { return program.help() } } @@ -232,12 +232,16 @@ if (options.lib) { webpackConfig.output.libraryTarget = 'umd' } else { // only output index.html in non-lib mode - webpackConfig.plugins.unshift( - new HtmlWebpackPlugin(Object.assign({ - title: 'Vue App', - template: ownDir('lib/template.html') - }, options.html)) - ) + var html = Array.isArray(options.html) ? options.html : [options.html || {}] + + html.forEach(item => { + webpackConfig.plugins.unshift( + new HtmlWebpackPlugin(Object.assign({ + title: 'Vue App', + template: ownDir('lib/template.html') + }, item)) + ) + }) } // installed by `yarn global add` @@ -284,7 +288,15 @@ if (production) { } else { if (!options.watch) { webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin()) - webpackConfig.entry.client.unshift(require.resolve('webpack-hot-middleware/client') + `?reload=true&path=http://${options.host}:${options.port}/__webpack_hmr`) + var hmrEntries = options.hmrEntries || ['client'] + var hmrClient = require.resolve('webpack-hot-middleware/client') + `?reload=true&path=http://${options.host}:${options.port}/__webpack_hmr` + hmrEntries.forEach(name => { + if (Array.isArray(webpackConfig.entry[name])) { + webpackConfig.entry[name].unshift(hmrClient) + } else { + webpackConfig.entry[name] = [hmrClient, webpackConfig.entry[name]] + } + }) } webpackConfig.devtool = 'eval-source-map' webpackConfig.plugins.push( @@ -316,8 +328,8 @@ if (!options.disableWebpackConfig) { } } -// only check entry when there's no custom `run` process -if (!options.run && !fs.existsSync(options.entry)) { +// only check entry when there's no custom config +if (!options.config && !fs.existsSync(options.entry)) { logger.fatal(`${chalk.yellow(options.entry)} does not exist, did you forget to create one?`) } diff --git a/docs/build.md b/docs/build.md index c08c522727..ab1b010211 100644 --- a/docs/build.md +++ b/docs/build.md @@ -143,7 +143,7 @@ PostCSS options, if it's an `Array` or `Function`, the default value will be ove #### html -Type: `Object` +Type: `Object` `Array` [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin) options, use this option to customize `index.html` output, default value: @@ -176,6 +176,13 @@ Type: `boolean` In production mode, all generated files will be compressed and produce sourcemaps file. You can use `--disableCompress` to disable this behavior. +#### hmrEntries + +Type: `Array`
+Default: `['client']` + +Add `webpack-hot-middleware` HMR client to specific webpack entries. By default your app is loaded in `client` entry, so we insert it here. + #### proxy Type: `string`, `Object` From c259e51286b3e4e7401e0d64850a1d00ca490448 Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Mon, 6 Feb 2017 00:36:46 +0800 Subject: [PATCH 2/5] read cli config --- bin/vue-build | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/vue-build b/bin/vue-build index 6a1e369a81..5d74dec79a 100755 --- a/bin/vue-build +++ b/bin/vue-build @@ -66,6 +66,7 @@ var options = merge({ host: 'localhost' }, localConfig, { entry: args[0], + config: program.config, port: program.port, host: program.host, open: program.open, From 536ce99d09e4c08a58446a71205a8b6add1d5b4b Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Mon, 6 Feb 2017 01:13:28 +0800 Subject: [PATCH 3/5] add hmr client after updating webpack config --- bin/vue-build | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/bin/vue-build b/bin/vue-build index 5d74dec79a..91b92bbece 100755 --- a/bin/vue-build +++ b/bin/vue-build @@ -287,18 +287,6 @@ if (production) { })) } } else { - if (!options.watch) { - webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin()) - var hmrEntries = options.hmrEntries || ['client'] - var hmrClient = require.resolve('webpack-hot-middleware/client') + `?reload=true&path=http://${options.host}:${options.port}/__webpack_hmr` - hmrEntries.forEach(name => { - if (Array.isArray(webpackConfig.entry[name])) { - webpackConfig.entry[name].unshift(hmrClient) - } else { - webpackConfig.entry[name] = [hmrClient, webpackConfig.entry[name]] - } - }) - } webpackConfig.devtool = 'eval-source-map' webpackConfig.plugins.push( new FriendlyErrorsPlugin(), @@ -329,6 +317,19 @@ if (!options.disableWebpackConfig) { } } +if (!options.watch && !options.production) { + webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin()) + var hmrEntries = options.hmrEntries || ['client'] + var hmrClient = require.resolve('webpack-hot-middleware/client') + `?reload=true&path=http://${options.host}:${options.port}/__webpack_hmr` + hmrEntries.forEach(name => { + if (Array.isArray(webpackConfig.entry[name])) { + webpackConfig.entry[name].unshift(hmrClient) + } else { + webpackConfig.entry[name] = [hmrClient, webpackConfig.entry[name]] + } + }) +} + // only check entry when there's no custom config if (!options.config && !fs.existsSync(options.entry)) { logger.fatal(`${chalk.yellow(options.entry)} does not exist, did you forget to create one?`) From 60cf4b2d84626a7d63d9b1d23bcf36791dcad51f Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Mon, 6 Feb 2017 01:19:18 +0800 Subject: [PATCH 4/5] allow to override webpack entry with options.entry --- bin/vue-build | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/vue-build b/bin/vue-build index 91b92bbece..4fffcda263 100755 --- a/bin/vue-build +++ b/bin/vue-build @@ -219,6 +219,10 @@ if (options.mount === undefined && !options.lib && /\.vue$/.test(options.entry)) if (options.mount) { webpackConfig.entry.client.push(ownDir('lib/default-entry.es6')) webpackConfig.resolve.alias['your-tasteful-component'] = cwd(options.entry) +} else if (Array.isArray(options.entry)) { + webpackConfig.entry.client = options.client +} else if (typeof options.entry === 'object') { + webpackConfig.entry = options.entry } else { webpackConfig.entry.client.push(options.entry) } From 9d012ebe04db5151be22d3034a46c1590e29a42f Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Mon, 6 Feb 2017 01:24:41 +0800 Subject: [PATCH 5/5] update docs --- docs/build.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/build.md b/docs/build.md index ab1b010211..24ec128580 100644 --- a/docs/build.md +++ b/docs/build.md @@ -80,10 +80,16 @@ You can define CLI options in this file. #### entry -Type: `string` +Type: `string` `Array` `Object` It's the first argument of `vue build` command, eg: `vue build entry.js`. You can set it here to omit it in CLI arguments. +The single-component mode (`--mount`) will not work if you set `entry` to an `Array` or `Object`. + +- `Array`: Override `webpackConfig.entry.client` +- `Object`: Override `webpackConfig.entry` +- `string`: Added to `webpackConfig.entry.client` or used as `webpackConfig.resolve.alias['your-tasteful-component']` in single-component mode. + #### port Type: `number`