mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
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:
parent
ec75ed11f6
commit
d7cb08b746
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user