我需要让 Angular 忽略某个js
文件在优化阶段(这样它就不会被优化/缩小)prod
建造。为此目的@angular-builders
包似乎是一个可行的解决方案。
我设置了angular.json
配置如下:
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./extended-webpack.config.js",
"mergeStrategies": {
"optimization": "replace"
}
},
构建configurations
如下面所述:
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
其余配置与正常用例相同。
The extended-webpack.config.js
看起来如下:
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
optimization: {
minimizer: [
new TerserPlugin({
exclude: ['./node_modules/<lib>/main.js']
}),
],
}
};
从我在构建中看到的情况来看,库仍然比原始版本最小化。这个配置是否适合我想要做的事情?