Source maps for css/sass
I am using the following setup:
Mac OSX El capitan angular-cli v1.0.0-beta.11-webpack.8, branch: master node 6.5.0 os: darwin x64 Using Sass
This might not be a bug with angular-cli, perhaps it is a limitation with angular2 but I am looking for anyone who's managed to solve this. I cannot get the sass to be source mapped. I want to inspect the CSS and see where a particular value is being set.
Personally, I am trying to work out how to edit the setup so I can do this locally. I am not too concerned in editing the webpack config, this is only going to be an issue in development, not production. But thinking globally, I think this should just work for anyone using angular-cli.
I have tried adding the source map commands here to webpack-build-common but no luck... I still see only the css in the head and nothing external.
I also saw another user trying something here with LESS, maybe I can do similar... https://github.com/angular/angular-cli/issues/1656#issuecomment-240983105
I also found this issue in the angular project but it appears to be fixed now.
This issue appears whether I use css, sass and whether I change ViewEncapsulation within the component or not.
I am not at all familiar with webpack and only angular 1.5 so please forgive me. Any help appreciated :)
Edit: here is my project setup
I managed to solve my issue by editing the webpack-build-common.ts file to have
{ exclude: styles, test: /\.scss$|\.sass$/, loaders: ["raw-loader", 'postcss-loader', 'sass-loader', "sass?sourceMap"] }
and
{ include: styles, test: /\.scss$|\.sass$/, loaders: ["style", "css?sourceMap", "sass?sourceMap"] }
instead of the previous loaders for those .scss tests. This seems to be OK for development so far.
@retallicka good job tracking it down!
@TheLarkInn is this something we should add to our config? I'm all for it if it helps users, and doesn't affect prod builds.
I'm using angular-cli 1.0.0-beta.16.
What I needed for my project was to be able to just track down CSS issues during development. Thanks to the hint from @retallicka, I edited webpack-build-common.js and changed
{
include: styles,
test: /\.css$/,
loaders: ['style-loader', 'css-loader', 'postcss-loader']
}
to
{
include: styles,
test: /\.css$/,
loaders: ['style-loader', 'css-loader?sourceMap', 'postcss-loader']
}
This seems to be working so far. But an option to enable/disable this from the CLI would be great. I presume that I will have to remove this change before building for production--is that right?
I also had to update to angular-cli: 1.0.0-beta.18 as 17 would generate an error when adding ?sourceMap.
However, I still can't get the source-maps to map correctly, the source maps are only pointing to the parent selector. Seen Here: #2826
@retallicka Are the SourceMaps pointing to the correct selector for you? If so can you post your webpack config file settings.
Thanks
Hi, I'm using 1.0.0-beta.20-4.
I was hoping that beta.20-4 would solve this issue but after updating from beta.19 the styles have lost the sourceMap and it's impossible to inspect in the browser, just the same as before applying the changes suggested by @retallicka but now I think that webpack-build-common.js has changed a lot and is not possible to apply this temporal solution again.
Any workaround please? Thanks a lot!
Reopening to investigate.
@filipesilva @TheLarkInn Please fixing this is quite important. The referenced PR fixes it: https://github.com/angular/angular-cli/pull/3272
Could you take a look and merge it, please? Thanks! Thanks also @mikejpeters !
I also have this problem in 1.0.0-beta.24, repo'd by doing ng new test, putting some css in styles.css and doing ng serve and then navigating to http://localhost:4200/styles.bundle.map results in
{"version":3,"sources":[],"names":[],"mappings":"","file":"styles.bundle.css","sourceRoot":""}
the js bundles seem to work as expected.
(i'm very new to angular 2 and angular cli so I might have missed a needed setting though)
It seems there might be something missing in https://github.com/angular/angular-cli/pull/3402 then. Will have to investigate.
@filipesilva hello, whats the current state?
cli-beta.26 stilll sourcemaps: http://localhost:4200/styles.bundle.map
//cli.json
styles: [
"style.scss"
]
ng serve --extract-css=true
@filipesilva quick fix that works for me: https://github.com/angular/angular-cli/pull/4219
@marekstabla I tried your fix but don't see any difference with a .css file. How did you test it was working?
I tried fiddling a bit more and it seems to work with a sourceMap (no s at the end) query. Will try to put up a PR with a fix and tests.
@filipesilva difference is inside map file (http://localhost:4200/styles.bundle.map) - looks low now it's properly generated
it works for me with s at the end - anyway let me know if that works for you :)
edit
double checked - it works only without s. Sorry!
https://github.com/webpack/css-loader seems to be the true origin of this problem, as we use LoaderOptionsPlugin to pass in the loader options.
Agreed. Looks like it ignores sourceMap option. Anyway others can use this as a workaround for now.
@filipesilva updated https://github.com/angular/angular-cli/pull/4219
Now it depends on buildOptions. At least it works for now since LoaderOptionsPlugin fails with css-loader
Added a more complete fix in #4222, including tests so we can be sure there are no regressions.
@filipesilva: It seems #4219 breaks CSS with sourcemaps enabled in some cases. Seems to be an issue with sourcemaps and css-loader when using urls with relative paths: https://github.com/webpack-contrib/css-loader/issues/232. Any ideas?
EDIT: Enabling extract CSS (e.g., ng serve --ec=true) solves this issue
It's not solution - it's workaround. Anyway I can confirm this bug. Perhaps we could enable css extract by default for dev mode? @filipesilva