improve server bundle size

explicitly excluding nuxt's node_modules optimizes bundle size in both normal usage and when using in test/linked/npx
This commit is contained in:
Pooya Parsa 2017-08-10 15:39:25 +04:30
parent ec75ed11f6
commit d7cb08b746
2 changed files with 16 additions and 9 deletions

View File

@ -51,13 +51,19 @@ 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
}))
}
const moduleDirs = [
this.options.modulesDir,
resolve(__dirname, '..', 'node_modules')
]
moduleDirs.forEach(dir => {
if (existsSync(dir)) {
config.externals.push(nodeExternals({
// load non-javascript files with extensions, presumably via loaders
whitelist: [/\.(?!(?:js|json)$).{1,5}$/i],
modulesDir: dir
}))
}
})
// --------------------------------------
// Production specific config

View File

@ -132,8 +132,9 @@ export default class Renderer extends Tapable {
// Create bundle renderer for SSR
this.bundleRenderer = createBundleRenderer(this.resources.serverBundle, Object.assign({
clientManifest: this.resources.clientManifest,
runInNewContext: false,
basedir: this.options.rootDir
runInNewContext: false
// Explicitly setting basedir makes problems with linked nuxt and npx
// basedir: this.options.rootDir
}, this.options.render.bundleRenderer))
// Promisify renderToString