使用 Angular 中的源映射生成生产版本 - CLI [英] Generate production build with sourcemaps in Angular - CLI

查看:20
本文介绍了使用 Angular 中的源映射生成生产版本 - CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在生产构建后保留源映射?

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"

我尝试将其更改为:

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

但没有任何改变.

如果我这样做:ng build --sourcemap 我得到了源映射,但是我得到了 index.html 而不是 index.prod.html.

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

是否可以编辑第一个命令来构建 sourcemap 文件?

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

这是我的 tsconfig.json 文件:

{
    "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"
        ]
    }
}

推荐答案

你应该像这样编辑你的 angular.json

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

然后运行

ng build --prod

但我不建议您在生产中打开源映射,因为它会增加包大小

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

这篇关于使用 Angular 中的源映射生成生产版本 - CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆