mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-21 07:59:33 +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://webpack.js.org/configuration/externals/#externals
|
||||||
// https://github.com/liady/webpack-node-externals
|
// https://github.com/liady/webpack-node-externals
|
||||||
if (existsSync(this.options.modulesDir)) {
|
const moduleDirs = [
|
||||||
|
this.options.modulesDir,
|
||||||
|
resolve(__dirname, '..', 'node_modules')
|
||||||
|
]
|
||||||
|
moduleDirs.forEach(dir => {
|
||||||
|
if (existsSync(dir)) {
|
||||||
config.externals.push(nodeExternals({
|
config.externals.push(nodeExternals({
|
||||||
// load non-javascript files with extensions, presumably via loaders
|
// load non-javascript files with extensions, presumably via loaders
|
||||||
whitelist: [/\.(?!(?:js|json)$).{1,5}$/i],
|
whitelist: [/\.(?!(?:js|json)$).{1,5}$/i],
|
||||||
modulesDir: this.options.modulesDir
|
modulesDir: dir
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// --------------------------------------
|
// --------------------------------------
|
||||||
// Production specific config
|
// Production specific config
|
||||||
|
@ -132,8 +132,9 @@ export default class Renderer extends Tapable {
|
|||||||
// Create bundle renderer for SSR
|
// Create bundle renderer for SSR
|
||||||
this.bundleRenderer = createBundleRenderer(this.resources.serverBundle, Object.assign({
|
this.bundleRenderer = createBundleRenderer(this.resources.serverBundle, Object.assign({
|
||||||
clientManifest: this.resources.clientManifest,
|
clientManifest: this.resources.clientManifest,
|
||||||
runInNewContext: false,
|
runInNewContext: false
|
||||||
basedir: this.options.rootDir
|
// Explicitly setting basedir makes problems with linked nuxt and npx
|
||||||
|
// basedir: this.options.rootDir
|
||||||
}, this.options.render.bundleRenderer))
|
}, this.options.render.bundleRenderer))
|
||||||
|
|
||||||
// Promisify renderToString
|
// Promisify renderToString
|
||||||
|
Loading…
Reference in New Issue
Block a user