【问题标题】:How to get sourcemaps out of Angular2 component styleUrls如何从 Angular2 组件 styleUrls 中获取源映射
【发布时间】:2016-11-23 16:31:26
【问题描述】:

我正在使用 Typescrypt 开发我的第一个 Angular2 应用程序。下面是一个组件的例子:

home.component.ts

import {Component} from '@angular/core';

@Component({
    moduleId: module.id,
    selector: 'home',
    templateUrl: 'home.component.html',
    styleUrls: ['home.component.css']
})

export class HomeComponent {
}

由于我必须处理 SASS 文件以获取特定于组件的 CSS,因此我创建了以下 Gulp 任务:

gulpfile.js

gulp.task('create:styles', function(cb) {
  return gulp.src('src/app/**/*.scss')
             .pipe(sourcemap.init())
             .pipe(sass().on('error', sass.logError))
             .pipe(sourcemap.write())
             .pipe(gulp.dest(paths.dist + '/app/'));
});

如您所见,我使用sourcemaps Gulp plugin 来映射样式的源文件。

据我所知,Angular 在 HTML <style> 元素中注入组件 CSS 文件。因此,源映射似乎不起作用。

您知道映射 CSS 的任何解决方法吗?我会弄清楚为什么我在浏览器的检查工具中看不到源文件(.scss)。 sourcemaps 插件有什么问题?

【问题讨论】:

    标签: css angular sass gulp source-maps


    【解决方案1】:

    答案是目前我们无能为力。该功能请求仍在 Angular2 Github 存储库中打开:enter link description here

    【讨论】:

      【解决方案2】:

      取自这篇SO answer和这篇文章https://medium.com/@IMM9O/angular-cli-some-special-cases-f48059fb33e5

      ng serve 上的这些标志包括源映射。

      ng serve -sm -ec
      

      或者

      ng serve --sourcemap --extractCss
      

      它不包括组件样式表的源映射,如您所问,但仅适用于 angular-cli.json 配置文件中包含的全局样式表。总比没有好,特别是因为在检查元素时,您可以推断出唯一没有映射到源文件而是映射到 <style> 标签的 CSS 是组件样式表的 CSS。

      我正在使用 angular-cli 版本1.0.0-rc.4

      【讨论】:

      猜你喜欢
      • 2020-03-27
      • 1970-01-01
      • 2022-11-30
      • 2017-09-10
      • 2015-12-23
      • 2013-01-20
      • 2011-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多