mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
refactor: extract customize webpack function (#3745)
This commit is contained in:
parent
a67136c6d6
commit
673a38216f
@ -260,6 +260,21 @@ export default class WebpackBaseConfig {
|
||||
return plugins
|
||||
}
|
||||
|
||||
customize(config) {
|
||||
if (typeof this.options.build.extend === 'function') {
|
||||
const extendedConfig = this.options.build.extend.call(this.builder, config, {
|
||||
isDev: this.options.dev,
|
||||
isServer: this.isServer,
|
||||
isClient: !this.isServer
|
||||
})
|
||||
// Only overwrite config when something is returned for backwards compatibility
|
||||
if (extendedConfig !== undefined) {
|
||||
return extendedConfig
|
||||
}
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
config() {
|
||||
// Prioritize nested node_modules in webpack search path (#2558)
|
||||
const webpackModulesDir = ['node_modules'].concat(this.options.modulesDir)
|
||||
|
@ -76,7 +76,7 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
||||
}
|
||||
|
||||
config() {
|
||||
let config = super.config()
|
||||
const config = super.config()
|
||||
|
||||
// Entry points
|
||||
config.entry = path.resolve(this.options.buildDir, 'client.js')
|
||||
@ -119,20 +119,6 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
||||
)
|
||||
}
|
||||
|
||||
// Extend config
|
||||
if (typeof this.options.build.extend === 'function') {
|
||||
const isDev = this.options.dev
|
||||
const extendedConfig = this.options.build.extend.call(this.builder, config, {
|
||||
isDev,
|
||||
isClient: true
|
||||
})
|
||||
|
||||
// Only overwrite config when something is returned for backwards compatibility
|
||||
if (extendedConfig !== undefined) {
|
||||
config = extendedConfig
|
||||
}
|
||||
}
|
||||
|
||||
// Make uglifyjs faster
|
||||
if (!this.options.dev && !config.optimization.minimizer) {
|
||||
// https://github.com/webpack-contrib/uglifyjs-webpack-plugin
|
||||
@ -153,6 +139,6 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
||||
]
|
||||
}
|
||||
|
||||
return config
|
||||
return this.customize(config)
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ export default class WebpackServerConfig extends BaseConfig {
|
||||
}
|
||||
|
||||
config() {
|
||||
let config = super.config()
|
||||
const config = super.config()
|
||||
|
||||
// Config devtool
|
||||
config.devtool = 'cheap-source-map'
|
||||
@ -75,19 +75,6 @@ export default class WebpackServerConfig extends BaseConfig {
|
||||
}
|
||||
})
|
||||
|
||||
// Extend config
|
||||
if (typeof this.options.build.extend === 'function') {
|
||||
const isDev = this.options.dev
|
||||
const extendedConfig = this.options.build.extend.call(this.builder, config, {
|
||||
isDev,
|
||||
isServer: true
|
||||
})
|
||||
// Only overwrite config when something is returned for backwards compatibility
|
||||
if (extendedConfig !== undefined) {
|
||||
config = extendedConfig
|
||||
}
|
||||
}
|
||||
|
||||
return config
|
||||
return this.customize(config)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user