@angular-builders - ignore certain script during in the optimisation phase

风格不统一 提交于 2020-01-05 04:11:02

问题


I need to make Angular ignore a certain js file during the optimization phase (so that it's not optimized/minified) in prod build. For this purpose the @angular-builders package seemed like a viable solution.

I setup the angular.json config as follows:

"architect": {
            "build": {
                "builder": "@angular-builders/custom-webpack:browser",
                "options": {
                    "customWebpackConfig": {
                        "path": "./extended-webpack.config.js",
                        "mergeStrategies": {
                          "optimization": "replace"
                        }
                    },

The build configurations are as follows:

"configurations": {
                    "production": {
                        "optimization": true,
                        "outputHashing": "all",
                        "sourceMap": false,
                        "extractCss": true,
                        "namedChunks": false,
                        "aot": true,
                        "extractLicenses": true,
                        "vendorChunk": false,
                        "buildOptimizer": true,

The rest of the configuration stays the same as for normal use-cases.

The extended-webpack.config.js looks like following:

const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
    optimization: {
        minimizer: [
            new TerserPlugin({
                exclude: ['./node_modules/<lib>/main.js']
            }),
        ],
    }
};

From what I see in the build the library is still minimized from the original version. Is this configuration correct for what I want to do?

来源:https://stackoverflow.com/questions/54607569/angular-builders-ignore-certain-script-during-in-the-optimisation-phase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!