angular-seed icon indicating copy to clipboard operation
angular-seed copied to clipboard

Add Sass support - css source mapping

Open danpii opened this issue 10 years ago • 10 comments

Hi, i've cloned your seed and followed the wiki description to add sass support (https://github.com/mgechev/angular2-seed/wiki/Add-Sass-support). The scss files are compiled correctly, but css source mapping is only working for main.scss.

Component scss files are compiled and copied into the corresponding folder, e.g. "dist/dev/app/+home/components/home.component.css". But when running dev mode (npm start),it seems all component css is injected as < style > tag and css source mapping doesn't work for me.

How could I get css source mapping work for component scss/css files. I think the same problem should also occur if sass support is not added.

danpii avatar Apr 19 '16 09:04 danpii

Angular injects the component-specific CSS files in <style> elements.

mgechev avatar Apr 19 '16 09:04 mgechev

is there a way to have a source mapping for these <stlye> elements to the original css files?

danpii avatar Apr 19 '16 11:04 danpii

@DanPii - @nareshbhatia runs a fork devoted to extending the seed to use the sass pre-compiler here https://github.com/archfirst/angular2-seed-sass

joshwiens avatar Apr 19 '16 14:04 joshwiens

On a more personal note, I have moved away from sass proper and opted to instead use a mix of precss & postcss features to retain the functionality without the headache of inlining sass/scss in my templates.

IMO it's worth considering

joshwiens avatar Apr 19 '16 14:04 joshwiens

@d3viant0ne i found your angular2-seed-postcss fork today and read some other opinions about postcss over sass. it really seems worth considering. I've got a sass project already that i would need to port to postcss, so i will check if all features are supported and how much changes are needed.

I've cloned @nareshbhatia angular2-seed-sass as well as your postcss fork. As mentioned by @mgechev Angular injects component css files as <style> elements. So source mapping is not working for this as well. @d3viant0ne Do you know a way to get source mapping working on Angular2's inline style?

danpii avatar Apr 19 '16 21:04 danpii

@DanPii - I tried for about a week to get it to work properly before I switched directions (postcss)

@nareshbhatia is in the same place that I was stuck on, the zone.js errors.

If I have some time this weekend, I may circle back around to it for the sake of not losing to software but given the performance gains I got out of postcss with 90% of the functionality it's honestly not terribly high on my list.

The path to get it working will require a function call to process your sass into css when the template is inlined but that runs your into zone.js throwing. Given Angular2's push towards RC, I unfortunately don't see whatever the issue is being resolved anytime soon.

Assuming I have the time this weekend, i'm going to work the issue on @nareshbhatia 's fork where he has an open issue archfirst/angular2-seed-sass#8 so we can focus everyones effort on the problem in the same place.

joshwiens avatar Apr 19 '16 22:04 joshwiens

@d3viant0ne thanks for the feedback. I'm still new to Angular and gulp tasks. But if I understand it correctly, shouldn't the source mapping problem apply to pure css (no SASS, no postcss) as well, because Angular injects component css files as inline style? Or is there another way?

danpii avatar Apr 20 '16 00:04 danpii

It's not so much about the component style at this point zone.js blows up trying to load the template.

  About component
    ✖ should work
      Chrome 49.0.2623 (Mac OS X 10.11.4)
      PhantomJS 2.1.1 (Mac OS X 0.0.0)
    Failed: Failed to load /Users/nbhati/projects/angular2-seed-sass/dist/dev/about/components/about.component.html
    invoke@/Users/nbhati/projects/angular2-seed-sass/node_modules/zone.js/dist/zone.js:308:34
    run@/Users/nbhati/projects/angular2-seed-sass/node_modules/zone.js/dist/zone.js:201:50
    /Users/nbhati/projects/angular2-seed-sass/node_modules/zone.js/dist/zone.js:553:61
    invokeTask@/Users/nbhati/projects/angular2-seed-sass/node_modules/zone.js/dist/zone.js:341:43
    runTask@/Users/nbhati/projects/angular2-seed-sass/node_modules/zone.js/dist/zone.js:238:58
    drainMicroTaskQueue@/Users/nbhati/projects/angular2-seed-sass/node_modules/zone.js/dist/zone.js:459:43

I'd have to go step through it again to tell you exactly what the issue was but essentially, you process the scss into css w/ sourcemaps and zone.js doesn't like what it's getting.

joshwiens avatar Apr 20 '16 01:04 joshwiens

The generated files are all properly created and in the proper place, it just blows up.

joshwiens avatar Apr 20 '16 01:04 joshwiens

As not seed specific issue, we can close it for now.

mgechev avatar Apr 20 '16 06:04 mgechev