Generate production build with sourcemaps in Angular - CLI

江枫思渺然 提交于 2020-12-11 05:55:06

问题


How to keep sourcemaps after production build?

Right now, my command looks like this:

"build-prod": "ng build --app=release -prod && cp -R lang dist"

I tried changing it to:

ng build --app=release --sourceMap=true -prod && cp -R lang dist

but nothing changed.

If I do: ng build --sourcemap I get sourcemaps but then I get index.html instead of index.prod.html.

Is it possible to edit the first command to build sourcemap files?

this is my tsconfig.json file:

{
    "compileOnSave": false,
    "compilerOptions": {
        "outDir": "./dist/out-tsc",
        "sourceMap": true,
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es5",
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2017",
            "dom"
        ]
    }
}

回答1:


You should edit your angular.json like this

"configurations": {
    "production": {
        "fileReplacements": [
            {
                "replace": "src/environments/environment.ts",
                "with": "src/environments/environment.prod.ts"
            }
        ],
        "optimization": true,
        "outputHashing": "all",
        "sourceMap": false, // change to true

Then run

ng build --prod

But I wouldnt recommend you turn on source map in production because it will increase a bundle size




回答2:


you can try

ng build --prod --source-map=true|false

angular.io/cli/build



来源:https://stackoverflow.com/questions/57660537/generate-production-build-with-sourcemaps-in-angular-cli

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