From bdb6791e400c97af1c8dce88665eda4cac3d1e0f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 3 Jan 2019 23:57:50 +0330 Subject: [PATCH] feat(webpack,cli): standalone build mode (#4661) * feat(webpack,cli): standalone build mode * revert typo --- packages/cli/src/commands/build.js | 10 ++++++++++ packages/config/src/config/build.js | 1 + packages/webpack/src/config/server.js | 22 ++++++++++++---------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/commands/build.js b/packages/cli/src/commands/build.js index 383c20ca81..0a7d153995 100644 --- a/packages/cli/src/commands/build.js +++ b/packages/cli/src/commands/build.js @@ -46,6 +46,16 @@ export default { options.build.quiet = !!argv.quiet } } + }, + standalone: { + type: 'boolean', + default: false, + description: 'Bundle all server dependencies (useful for nuxt-start)', + prepare(cmd, options, argv) { + if (argv.standalone) { + options.build.standalone = true + } + } } }, async run(cmd) { diff --git a/packages/config/src/config/build.js b/packages/config/src/config/build.js index 4505033fb0..1b0b5de7fa 100644 --- a/packages/config/src/config/build.js +++ b/packages/config/src/config/build.js @@ -10,6 +10,7 @@ export default () => ({ ssr: undefined, parallel: false, cache: false, + standalone: false, publicPath: '/_nuxt/', filenames: { // { isDev, isClient, isServer } diff --git a/packages/webpack/src/config/server.js b/packages/webpack/src/config/server.js index 3903b767eb..5ecf947d90 100644 --- a/packages/webpack/src/config/server.js +++ b/packages/webpack/src/config/server.js @@ -86,16 +86,18 @@ export default class WebpackServerConfig extends WebpackBaseConfig { // https://webpack.js.org/configuration/externals/#externals // https://github.com/liady/webpack-node-externals // https://vue-loader.vuejs.org/migrating.html#ssr-externals - this.options.modulesDir.forEach((dir) => { - if (fs.existsSync(dir)) { - config.externals.push( - nodeExternals({ - whitelist: this.whitelist, - modulesDir: dir - }) - ) - } - }) + if (!this.options.build.standalone && !this.options.dev) { + this.options.modulesDir.forEach((dir) => { + if (fs.existsSync(dir)) { + config.externals.push( + nodeExternals({ + whitelist: this.whitelist, + modulesDir: dir + }) + ) + } + }) + } return config }