mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
feat(builder): allow to customize or disable minimizer plugins (#4018)
* feat(builder): allow to customize or disable minimizer plugins * feat: support optimization.minimize https://webpack.js.org/configuration/optimization/#optimization-minimize * fix typos
This commit is contained in:
parent
1bf6385d48
commit
8f06a187db
@ -99,11 +99,14 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
|||||||
extendConfig() {
|
extendConfig() {
|
||||||
const config = super.extendConfig(...arguments)
|
const config = super.extendConfig(...arguments)
|
||||||
|
|
||||||
if (!this.options.dev && !config.optimization.minimizer) {
|
// Add minimizer plugins
|
||||||
|
if (config.optimization.minimize && config.optimization.minimizer === undefined) {
|
||||||
config.optimization.minimizer = []
|
config.optimization.minimizer = []
|
||||||
|
|
||||||
// https://github.com/webpack-contrib/terser-webpack-plugin
|
// https://github.com/webpack-contrib/terser-webpack-plugin
|
||||||
const terserJsPlugin = new TerserWebpackPlugin({
|
if (this.options.build.terser) {
|
||||||
|
config.optimization.minimizer.push(
|
||||||
|
new TerserWebpackPlugin(Object.assign({
|
||||||
parallel: true,
|
parallel: true,
|
||||||
cache: this.options.build.cache,
|
cache: this.options.build.cache,
|
||||||
sourceMap: config.devtool && /source-?map/.test(config.devtool),
|
sourceMap: config.devtool && /source-?map/.test(config.devtool),
|
||||||
@ -115,15 +118,17 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
|||||||
comments: /^\**!|@preserve|@license|@cc_on/
|
comments: /^\**!|@preserve|@license|@cc_on/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}, this.options.build.terser))
|
||||||
config.optimization.minimizer.push(terserJsPlugin)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// https://github.com/NMFR/optimize-css-assets-webpack-plugin
|
// https://github.com/NMFR/optimize-css-assets-webpack-plugin
|
||||||
// https://github.com/webpack-contrib/mini-css-extract-plugin#minimizing-for-production
|
// https://github.com/webpack-contrib/mini-css-extract-plugin#minimizing-for-production
|
||||||
// TODO: Remove OptimizeCSSAssetsPlugin when upgrading to webpack 5
|
// TODO: Remove OptimizeCSSAssetsPlugin when upgrading to webpack 5
|
||||||
if (this.options.build.extractCSS) {
|
if (this.options.build.optimizeCSS) {
|
||||||
const optimizeCSSPlugin = new OptimizeCSSAssetsPlugin({})
|
config.optimization.minimizer.push(
|
||||||
config.optimization.minimizer.push(optimizeCSSPlugin)
|
new OptimizeCSSAssetsPlugin(Object.assign({}, this.options.build.optimizeCSS))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,8 +87,12 @@ export default {
|
|||||||
},
|
},
|
||||||
styleResources: {},
|
styleResources: {},
|
||||||
plugins: [],
|
plugins: [],
|
||||||
|
terser: {},
|
||||||
|
optimizeCSS: undefined,
|
||||||
optimization: {
|
optimization: {
|
||||||
runtimeChunk: 'single',
|
runtimeChunk: 'single',
|
||||||
|
minimize: undefined,
|
||||||
|
minimizer: undefined,
|
||||||
splitChunks: {
|
splitChunks: {
|
||||||
chunks: 'all',
|
chunks: 'all',
|
||||||
automaticNameDelimiter: '.',
|
automaticNameDelimiter: '.',
|
||||||
|
@ -239,6 +239,16 @@ Options.from = function (_options) {
|
|||||||
options.build.extractCSS = false
|
options.build.extractCSS = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable minimize for production builds
|
||||||
|
if (options.build.optimization.minimize === undefined) {
|
||||||
|
options.build.optimization.minimize = !options.dev
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable optimizeCSS only when extractCSS is enabled
|
||||||
|
if (options.build.optimizeCSS === undefined) {
|
||||||
|
options.build.optimizeCSS = options.build.extractCSS ? {} : false
|
||||||
|
}
|
||||||
|
|
||||||
const loaders = options.build.loaders
|
const loaders = options.build.loaders
|
||||||
const vueLoader = loaders.vue
|
const vueLoader = loaders.vue
|
||||||
if (vueLoader.productionMode === undefined) {
|
if (vueLoader.productionMode === undefined) {
|
||||||
|
Loading…
Reference in New Issue
Block a user