diff --git a/bin/vue-build b/bin/vue-build index 16919f5fdc..3e786b4a93 100755 --- a/bin/vue-build +++ b/bin/vue-build @@ -288,7 +288,7 @@ if (!options.disableWebpackConfig) { if (typeof options.webpack === 'object') { webpackConfig = webpackMerge.smart(webpackConfig, options.webpack) } else if (typeof options.webpack === 'function') { - webpackConfig = options.webpack(webpackConfig, options, webpack) + webpackConfig = options.webpack(webpackConfig, options, webpack) || webpackConfig } else { var localWebpackConfigPath = typeof options.webpack === 'string' ? cwd(options.webpack) @@ -313,7 +313,9 @@ try { checkEntryExists(options.entry) -if (options.watch) { +if (typeof options.run === 'function') { + options.run(webpackConfig, options) +} else if (options.watch) { console.log('> Running in watch mode') rm(path.join(options.dist, '*')) compiler.watch({}, (err, stats) => handleBuild(err, stats, true)) diff --git a/docs/build.md b/docs/build.md index c014456c53..ba5c8db811 100644 --- a/docs/build.md +++ b/docs/build.md @@ -219,6 +219,29 @@ module.exports = { } ``` +#### run(webpackConfig, options) + +Type: `function` + +You can use a custom `run` function to perform your own build process instead of the default one. For example, run karma with the processed webpack config: + +```js +const Server = require('karma').Server + +module.exports = { + run(webpackConfig) { + const server = new Server({ + webpack: webpackConfig, + // other karma options... + }, exitCode => { + console.log('Karma has exited with ' + exitCode) + process.exit(exitCode) + }) + server.start() + } +} +``` + ### webpack.config.js All the webpack options are available here.