问题描述
生产构建后如何保留源地图?
How to keep sourcemaps after production build?
现在,我的命令如下:
"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.
是否可以编辑第一个命令来构建源地图文件?
Is it possible to edit the first command to build sourcemap files?
这是我的tsconfig.json文件:
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"
]
}
}
推荐答案
您应像这样编辑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中使用Sourcemap生成生产版本-CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!