有了这个使用 webpack-encore 的 webpack.config.js,并用 terser 缩小,我可以成功编译,但绝对没有任何东西被缩小。注释和完整的变量名称仍然存在。
var Encore = require('@symfony/webpack-encore');
const TerserPlugin = require('terser-webpack-plugin');
Encore
// the project directory where compiled assets will be stored
.setOutputPath('public/build/')
.setPublicPath('/build')
// the public path used by the web server to access the previous directory
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())
.enableReactPreset()
.enableSassLoader()
.enableLessLoader()
.autoProvidejQuery()
.disableSingleRuntimeChunk()
.addEntry('app_prescription', [
'./assets/js/prescription/app_prescription.js'
])
.addLoader({
test: /\.jsx?$/,
exclude: /node_modules/,
loader: "babel-loader?cacheDirectory"
})
;
if( Encore.isProduction() ) {
Encore.addPlugin(new TerserPlugin({parallel: true,cache:true}) );
}
module.exports = function(env) {
Encore.enableVersioning();
const config = Encore.getWebpackConfig() ;
if( Encore.isProduction() ) {
config.optimization = {
minimizer: [new TerserPlugin({parallel: true,cache:true})]
}
}
return config ;
}
这段代码有什么问题?