这是由于Angular CLI的一个问题自v1.3.2以来一直处于打开和关闭状态,目前从v1.7起仍处于关闭状态。x个
做了更多的挖掘&比较webpack配置文件,发现新的CLI使用的webpack插件“raw loader”还不支持sourcemap(不知何故,票证已关闭,但我不确定sourcemap是否已实现)。
唯一的选择是降级到v1.6.6,然后应用@CharltonC提供的补丁
在“节点”中_modules@angular\cli\models\webpack configs\common。js”文件,在第162行中,在getCommonConfig函数中返回的公共配置对象中添加一行devtool:“source map”,例如。
...
catch (e) { }
return {
devtool: 'source-map', // add this line
resolve: {
extensions: ['.ts', '.js'],
...
在终端中使用以下命令进行测试(也适用于Sass@import):
ng serve // no sourcemap
ng serve -sm -ec // has sourcemap
ng serve --sourcemap --extract-css // has sourcemap
ng serve --sourcemap --extractCss // has sourcemap
https://github.com/angular/angular-cli/issues/9099