-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Source Maps #125
Comments
@shannonmoeller please correct me if I'm wrong but source maps are for CSS preprocessors only. And apparently clean-css makes smaller CSS from… larger CSS! |
Source maps are for any JS or CSS files that are compiled from other source files. Because clean-css inlines @imports and modifies code to make it smaller than the source files, it qualifies! Consider your JS sister, uglifyjs. It only makes smaller JS files from larger JS files, and it supports generating source maps too! |
Ah, sneaky |
+1 |
@Kienz we have some other tasks in the pipeline but we won't leave it unanswered. The more +1's the quicker we get into it. |
+1 This will be one of the most useful feature. |
+1, we'd prefer to use |
@GoalSmashers sounds great, count me in for testing if needed |
@GoalSmashers sounds awesome 👍 . |
When doing it please could you consider allowing passing in a source sourcemap as well? Uglifjs also allows this and I think If you use mozillas sourcemap library (on node) then it allows integrating it. I implemented css sourcemap support for less and it would be great to allow less to use clean css to compress the css and transform the sourcemap too. |
@lukeapage You stole the words out of my mouth :D +1 for the suggestion. |
@lukeapage @sbspk Sure, I'll take a look into it! |
+1 |
+1 |
Looking forward to this an willing to help test out in any way I can. |
👍 |
I'm not sure how this can be done without an AST (and LESS does create a source map, so it might be worth looking at what they're doing for compressing. |
@OliverJAsh I've been thinking a lot about it and we may need an AST-like structure to add source maps but there could be another option as well. Need to play a bit more with it to see what fits the best. |
+1 |
1 similar comment
+1 |
+1 This feature would be sooooo useful! |
+1 |
1 similar comment
+1 |
+1 |
+1 :) |
* Per discussion with Luke Page (see #125) it is used in case of shortened variables so probably useless when it comes to CSS.
Good news: I've tested it thoroughly during the last 2 days on my biggest project and it seems to works fine with the latest tweaks. I tested 2 cases - no input source maps, just plain source CSS => minified CSS, and LESS => CSS => minified CSS, and in both cases it shows up fine in Chrome and Firefox. The remaining two pieces is to check Windows + IE11 (they have source maps, right?) and write some docs on how to use it. Expect a merge to master soon! |
@lukeapage I also created #397 for adding support for styles embedded in input source map. |
Happy days, this is awesome. I'm glad I found this repo, and this thread ;-) Thanks for work on source maps. 👍 I am trying to get source maps working in broccoli-clean-css plugin. This line makes |
* Per discussion with Luke Page (see #125) it is used in case of shortened variables so probably useless when it comes to CSS.
@naartjie Sure thing! 💯 Regarding your question, that line applies when you provide input without a reference to a file. On the other hand if you pass a file, then clean-css will get all source map info from it. We use the following trick to handle multiple input files correctly in CLI but I'm thinking about adding it to API too. See: https://github.com/jakubpawlowicz/clean-css/blob/master/bin/cleancss#L107 |
@jakubpawlowicz Nice magic trick with the This code gives an absolute path in the var cleanCss = new CleanCss({sourceMap: true, root: rootDir});
var mini = cleanCss.minify('@import url('+ relativeFilePath +');'); I tried setting This is working nicely for plain css files. I haven't tried with files which have source maps already, that'll be the next step, use it on files produced by a sass precompiler. |
@naartjie Sure, just use target option pointing to a directory, e.g.
Here's some more info: https://github.com/jakubpawlowicz/clean-css#how-to-rebase-relative-image-urls |
I've been able to confirm it works fine with Safari 7, but I have no idea if it does in Explorer 11. That won't block merging it into master, though. |
@naartjie Btw, it'd be pretty awesome if you could give SASS + clean-css a try. |
I consider the initial version of source maps as ready for 3.0 unless someone finds any bug(s). 🍻 |
@jakubpawlowicz sure, I'm trying to get to it, I just ran into some problems this eve: #563 #565 |
When I changed |
🍺 awesome! hope it ends up in the grunt-contrib-cssmin repo soon as well 👍 |
@naartjie would you be able to share your code? I can take a look later today. |
I've been able to verify that SASS source maps work fine too. I'll merge the branch to master now so please open a new issue if you spot anything wrong about source maps. |
I can also verify from my side, that SASS source maps in are working. Sorry it took a while. 👍 for merging it into master. Super cool. Edit: just to be clear on this, I had to use version 3.0 of libsass for this to work, as it wasn't working on more recent libsass versions. |
Great, thanks @naartjie for the feedback! |
Sure thing. Here is a self contained test, which should exemplify my understanding of it: var fs = require('fs');
var CleanCss = require('clean-css');
fs.writeFileSync('./my.css', 'body {color:red;}');
var cleanCss = new CleanCss({ sourceMap: true, target: process.cwd() });
var out = cleanCss.minify('@import url(my.css)').sourceMap.toString();
// out = {"version":3,"sources":[],"names":[],"mappings":""} I'm sure I'm just doing something silly, or misunderstanding your instructions somehow. Thanks for looking into it. |
That's how you should do it, however you're missing a semicolon in import: |
Doh! that fixes it. Told you it was silly!! ;-) Thanks a mil!! |
:-) Cheers! |
rhymes with... 🍻 |
I'll sure have once 3.0 is out :-D |
Would be awesome to have sourceMap support.
https://developers.google.com/chrome-developer-tools/docs/css-preprocessors#toc-css-preprocessor-support
The text was updated successfully, but these errors were encountered: