2020-10-27 14:42:46 +08:00
|
|
|
const CompressionWebpackPlugin = require('compression-webpack-plugin')
|
|
|
|
|
2020-10-27 11:20:36 +08:00
|
|
|
module.exports = {
|
|
|
|
pluginOptions: {
|
|
|
|
i18n: {
|
|
|
|
locale: 'en',
|
|
|
|
fallbackLocale: 'en',
|
|
|
|
localeDir: 'locales',
|
|
|
|
enableInSFC: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
publicPath: process.env.NODE_ENV === 'production' ? '' : '/',
|
|
|
|
productionSourceMap: false,
|
2020-10-27 14:42:46 +08:00
|
|
|
configureWebpack: config => {
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
config.plugins.push(
|
|
|
|
new CompressionWebpackPlugin({
|
|
|
|
// 正在匹配需要压缩的文件后缀
|
|
|
|
test: /\.(js|css|svg|woff|ttf|json|html)$/,
|
|
|
|
threshold: 10240,
|
|
|
|
deleteOriginalAssets: true
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
2020-10-27 11:20:36 +08:00
|
|
|
chainWebpack: config => {
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
config.output.filename('js/[name].js').end();
|
|
|
|
config.output.chunkFilename('js/[name].js').end();
|
|
|
|
// 修改生产配置
|
|
|
|
config.plugin('extract-css').tap(() => [{
|
|
|
|
filename: `css/[name].css`,
|
|
|
|
chunkFilename: `css/[name].css`
|
|
|
|
}])
|
|
|
|
}
|
|
|
|
config.module
|
|
|
|
.rule('fonts')
|
|
|
|
.use('url-loader')
|
|
|
|
.loader('url-loader')
|
|
|
|
.tap(options => {
|
|
|
|
options.fallback.options.name = 'fonts/[name].[ext]';
|
|
|
|
return options
|
|
|
|
});
|
|
|
|
// px2rem-loader
|
|
|
|
config.module
|
|
|
|
.rule('px2rem-loader')
|
|
|
|
.test(/\.css$/)
|
|
|
|
.use('px2rem-loader')
|
|
|
|
.loader('px2rem-loader')
|
|
|
|
.options({remUnit: 75})
|
|
|
|
.end()
|
|
|
|
}
|
|
|
|
}
|