diff --git a/lib/builder/webpack/server.config.js b/lib/builder/webpack/server.config.js index 1b8402caa2..9d4b1eb949 100644 --- a/lib/builder/webpack/server.config.js +++ b/lib/builder/webpack/server.config.js @@ -3,6 +3,7 @@ import VueSSRServerPlugin from 'vue-server-renderer/server-plugin' import nodeExternals from 'webpack-node-externals' import { each } from 'lodash' import { resolve } from 'path' +import { existsSync } from 'fs' import base from './base.config.js' /* @@ -34,15 +35,7 @@ export default function webpackServerConfig () { hints: false, maxAssetSize: Infinity }, - externals: [ - // https://webpack.js.org/configuration/externals/#externals - // https://github.com/liady/webpack-node-externals - nodeExternals({ - // load non-javascript files with extensions, presumably via loaders - whitelist: [/\.(?!(?:js|json)$).{1,5}$/i], - modulesDir: this.options.modulesDir - }) - ], + externals: [], plugins: (config.plugins || []).concat([ new VueSSRServerPlugin({ filename: 'server-bundle.json' @@ -56,6 +49,16 @@ export default function webpackServerConfig () { ]) }) + // https://webpack.js.org/configuration/externals/#externals + // https://github.com/liady/webpack-node-externals + if (existsSync(this.options.modulesDir)) { + config.externals.push(nodeExternals({ + // load non-javascript files with extensions, presumably via loaders + whitelist: [/\.(?!(?:js|json)$).{1,5}$/i], + modulesDir: this.options.modulesDir + })) + } + // -------------------------------------- // Production specific config // --------------------------------------