如何配置 angular-cli 来创建内联源映射? [英] How to configure angular-cli to create inline sourcemaps?
问题描述
angular.json 仅提供打开/关闭源映射生成的选项,但默认情况下它位于单独的文件中.
angular.json only gives the option to turn on/off sourcemap generation but by default it's in separate files.
tsconfig.json 也提供了 inlineSources 选项,但它被 angular-cli 忽略.
tsconfig.json gives also the inlineSources option but it's ignored by angular-cli.
有没有办法告诉 angular-cli 在 .js 中编写源映射?
Is there a way to tell angular-cli to write the source maps inside the .js?
推荐答案
对于可能关心的人,这里是我实现的方法,用于在 Android 设备上启用带有源映射支持的调试
To whom it may concern, here is the approach I implemented to enable debugging with source maps support on Android devices
- 通过运行
npx ng add ngx-build-plus
安装 ngx-build-plus这将安装所需的 npm 包并根据需要更新 angular.json更多详情请参阅https://github.com/manfredsteyer/ngx-build-plus一个> - 在项目根目录创建新文件
build-customization-plugin.js
,并在该文件中添加以下内容
- install ngx-build-plus by running
npx ng add ngx-build-plus
This will install the required npm package and update angular.json as required For more details please see https://github.com/manfredsteyer/ngx-build-plus - create new file
build-customization-plugin.js
in the project root directory and add the below content in this file
var merge = require('webpack-merge');
exports.default = {
config: function (cfg) {
const strategy = merge.strategy({
'devtool': 'replace',
});
return strategy(cfg, {
devtool: 'inline-source-map'
});
}
}
- 从根目录运行
ng build --eval-source-map --plugin ~build-customization-plugin.js
以使用源映射构建项目以在 Android 设备上进行调试 - run
ng build --eval-source-map --plugin ~build-customization-plugin.js
from the root directory to build the project with source maps to debug on Android devices
这是一种比我在之前的端口中描述的更改 angular/cli 源更好的方法:)
This is a better approach then changing angular/cli source as I described in a previous port :)
这篇关于如何配置 angular-cli 来创建内联源映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!