angular.json提供了打开/关闭sourcemap生成选项,但默认情况下会生成单独的文件。
tsconfig.json也提供了inlineSources选项,但由于angular-cli的原因被忽略了。
有没有一种方法可以告诉angular-cli将源映射写入.js文件内?
angular.json提供了打开/关闭sourcemap生成选项,但默认情况下会生成单独的文件。
tsconfig.json也提供了inlineSources选项,但由于angular-cli的原因被忽略了。
有没有一种方法可以告诉angular-cli将源映射写入.js文件内?
npx ng add ngx-build-plus
安装 ngx-build-plusbuild-customization-plugin.js
并添加以下内容: 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 设备上进行调试。这比我之前描述的更改 angular/cli 源代码的方法更好 :)
使用Angular 12时,步骤与@alex-ryltsov提到的相同,但有一些变化:
npx ng add ngx-build-plus
build-customization-plugin.js
:const { merge } = require("webpack-merge");
exports.default = {
config: function (cfg) {
return merge(cfg, {
devtool: "inline-source-map",
});
},
};
ng build --plugin ~build-customization-plugin.js
这是不支持的。为了实现这一点,我修补了 Angular CLI 源代码(我的 @angular/cli 版本为 7.0.0),以使用 inline-source-maps Webpack 选项。为此,我更改了 node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js 文件中的一行。
sourcemaps = 'eval';
到
sourcemaps = 'inline-source-map';
Angular 16的调整:
npx ng add ngx-build-plus
build-customization-plugin.js
:// See https://github.com/ionic-team/ionic-framework/issues/16455#issuecomment-751963968
const { merge } = require("webpack-merge");
const webpack = require("webpack");
exports.default = {
config: function (cfg) {
const result = merge(cfg, {
devtool: "inline-source-map",
});
// then we find SourceMapDevToolPlugin and remove it
// This is because we should never use both the devtool option and plugin together.
// The devtool option adds the plugin internally so you would end up with the plugin applied twice.
// See https://webpack.js.org/configuration/devtool/
const index = result.plugins.findIndex((plugin) => {
return plugin instanceof webpack.SourceMapDevToolPlugin;
});
result.plugins.splice(index, 1);
return result;
}
}
ng build --plugin ~build-customization-plugin.js
(或者如果你的shell将"~"替换为你的主目录,则使用ng build --plugin '~/path-to-script-relative-to-package-json/build-customization-plugin.js'
)。
ngx-build-plus
与最新版本的 Angular 不兼容。错误:Cannot read property 'architect' of undefined
。我无法理解 Angular CLI 开发人员决定反对这个选项。因为它非常容易实现。只需要一个带有可选webpack.config.js
的选项。没有这个官方选项,我们必须依赖第三方库。而在这种情况下,它不起作用。真是令人痛苦... - Domske