mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 23:52:06 +00:00
feat: optionally strip non-client or non-server code (#6149)
This commit is contained in:
parent
e9945b0896
commit
75bb0884cb
@ -59,6 +59,7 @@ export default () => ({
|
||||
plugins: [],
|
||||
terser: {},
|
||||
hardSource: false,
|
||||
aggressiveCodeRemoval: false,
|
||||
optimizeCSS: undefined,
|
||||
optimization: {
|
||||
runtimeChunk: 'single',
|
||||
|
@ -20,6 +20,7 @@ Object {
|
||||
"build": Object {
|
||||
"_publicPath": "/_nuxt/",
|
||||
"additionalExtensions": Array [],
|
||||
"aggressiveCodeRemoval": false,
|
||||
"analyze": false,
|
||||
"babel": Object {
|
||||
"babelrc": false,
|
||||
|
@ -7,6 +7,7 @@ Object {
|
||||
"alias": Object {},
|
||||
"build": Object {
|
||||
"additionalExtensions": Array [],
|
||||
"aggressiveCodeRemoval": false,
|
||||
"analyze": false,
|
||||
"babel": Object {
|
||||
"babelrc": false,
|
||||
@ -360,6 +361,7 @@ Object {
|
||||
"alias": Object {},
|
||||
"build": Object {
|
||||
"additionalExtensions": Array [],
|
||||
"aggressiveCodeRemoval": false,
|
||||
"analyze": false,
|
||||
"babel": Object {
|
||||
"babelrc": false,
|
||||
|
@ -115,7 +115,7 @@ export default class WebpackBaseConfig {
|
||||
}
|
||||
|
||||
if (!options.babelrc && !options.presets) {
|
||||
options.presets = [ defaultPreset ]
|
||||
options.presets = [defaultPreset]
|
||||
}
|
||||
|
||||
return options
|
||||
@ -141,6 +141,12 @@ export default class WebpackBaseConfig {
|
||||
'process.mode': JSON.stringify(this.mode),
|
||||
'process.static': this.buildContext.isStatic
|
||||
}
|
||||
if (this.buildContext.buildOptions.aggressiveCodeRemoval) {
|
||||
env['typeof process'] = JSON.stringify(this.isServer ? 'object' : 'undefined')
|
||||
env['typeof window'] = JSON.stringify(!this.isServer ? 'object' : 'undefined')
|
||||
env['typeof document'] = JSON.stringify(!this.isServer ? 'object' : 'undefined')
|
||||
}
|
||||
|
||||
Object.entries(this.buildContext.options.env).forEach(([key, value]) => {
|
||||
env['process.env.' + key] =
|
||||
['boolean', 'number'].includes(typeof value)
|
||||
|
@ -34,13 +34,16 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
||||
}
|
||||
|
||||
env () {
|
||||
return Object.assign(super.env(), {
|
||||
'process.env.VUE_ENV': JSON.stringify('client'),
|
||||
'process.browser': true,
|
||||
'process.client': true,
|
||||
'process.server': false,
|
||||
'process.modern': false
|
||||
})
|
||||
return Object.assign(
|
||||
super.env(),
|
||||
{
|
||||
'process.env.VUE_ENV': JSON.stringify('client'),
|
||||
'process.browser': true,
|
||||
'process.client': true,
|
||||
'process.server': false,
|
||||
'process.modern': false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
optimization () {
|
||||
|
@ -26,13 +26,16 @@ export default class WebpackServerConfig extends WebpackBaseConfig {
|
||||
}
|
||||
|
||||
env () {
|
||||
return Object.assign(super.env(), {
|
||||
'process.env.VUE_ENV': JSON.stringify('server'),
|
||||
'process.browser': false,
|
||||
'process.client': false,
|
||||
'process.server': true,
|
||||
'process.modern': false
|
||||
})
|
||||
return Object.assign(
|
||||
super.env(),
|
||||
{
|
||||
'process.env.VUE_ENV': JSON.stringify('server'),
|
||||
'process.browser': false,
|
||||
'process.client': false,
|
||||
'process.server': true,
|
||||
'process.modern': false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
optimization () {
|
||||
|
Loading…
Reference in New Issue
Block a user