Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Source Map Angular CLI css files in Chrome Dev Tools?

Is there a way to source-map styles so that edits made in Chrome Dev Tools can be persisted to a added local Workspace?

Chrome Dev Tools is showing all my styles in styles.scss in a <style>...</style> tag in the element inspector.

enter image description here

enter image description here

I've setup Chrome Dev Tools workspaces similar to how @vt5491 did it in their SO here: https://stackoverflow.com/a/37627935/1762493 and that is working for the .ts files I believe but element styles don't link back to source maps in the element inspect as they've been built with ng serve into index.html's <style> element it seems.

  • I'm running ng serve -dev -p=8081
  • and tried ng serve -dev -p=8081 --aot=true but got a ENONET ng.factory.js missing error
  • I tried putting styles in app.component.css versus styles.scss
  • I tried this with ng build but it also puts all styles into index.html's <style>

Is this just the way it is currently with the Angular CLI? Maybe tweaking the web-pack underneath? It seems to be adding <style> tags per compiled stylesheet. If this is how the CLI is working currently then maybe this isn't just a question but a feature request because we are doing front-end work right, so having this working would save time.

Related to:

  • How to save CSS Style changes to ANGULAR 2.0 components form within Chrome Developer Tools?
  • Angular-cli not generating typescript files with --dev option
  • How to debug angular 2 app using angular-cli webpack? (in WebStorm)
  • SCSS SourceMap pointing to the Parent selector only.
    • github.com/angular/angular-cli Issue #2826

Thanks for any advice offered.

like image 274
Mikeumus Avatar asked Oct 20 '16 19:10

Mikeumus


People also ask

How do I add CSS to Chrome dev tools?

Go to element panel ( Ctrl + Shift + p and type show element panel). Scroll to the head element right click on the element and choose Edit as HTML, go to the bottom of that element ( Ctrl + End ), add your <style></style> element there add your style in that element, and hit Ctrl + Enter .

How do I enable CSS maps in Chrome?

UPDATE: With Chrome 30 out the door, CSS source map support has been promoted to a stable web developer tools feature. No need to enable Developer Tools experiments, simply open the settings window (the gear in the bottom right corner) and ensure Enable CSS source maps is ticked under Sources and you are good to go.

How do I find my CSS console in Chrome?

Testing CSS Selectors Using the Chrome Dev Console Otherwise, you can get here by clicking on the three dots to the top-right of your Chrome browser -> More Tools -> Developer Tools.


2 Answers

When you type ng serve by default angular cli doesn't include sourcemaps files for css files but you can include it by typing this command

ng serve -sm -ec

or

ng serve --sourcemap --extractCss

I use Angular Cli -v 1.0.3, and More information - Angular CLI special cases

like image 153
Serhiy Koziuk Avatar answered Sep 29 '22 06:09

Serhiy Koziuk


Angular-cli uses webpack, but it comes with its own configuration files in /node_modules/angular-cli/models.

You can modify them, but if you upgrade angular-cli it will overwrite your files. So make sure to back them up.

Yes, it is meant to go inline <style> tags. I agree that this seems weird and should be in a separate file, mainly so it can be cached by the user and reduce your views chunk size. It might be that they think inline is good as when you're in development mode you don't want it cached, which is fine, but on 'ng build' it should be compiled to its own file.

I know you can configure webpack to do that using the "extract-text-webpack-plugin", but I am not too familiar with it.

I would like to see angular-cli do that on build or have an option in the configuration for that.

like image 20
ggedde Avatar answered Sep 29 '22 07:09

ggedde