-
Notifications
You must be signed in to change notification settings - Fork 322
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
Should clean-css read CSS from the file system when passing the input as hash? #791
Comments
Here are some tests when input is passed as a hash: https:/jakubpawlowicz/clean-css/blob/master/test/module-test.js#L480 and code processing input hashes: https:/jakubpawlowicz/clean-css/blob/master/lib/utils/source-reader.js#L60. I am pretty sure clean-css does not try to load those files from disk. |
This is probably my misunderstanding of the hash data feature. I assumed that when given multiple CSS files on input:
clean-css would resolve the import without reading two.css from the file system. A test case would look similar to:
I'm assuming that's not the way clean-css was designed to work? |
Interesting use case. Why using it that way? Is that a metalsmith-specific flow? |
Metalsmith runs each file it processes through a pipeline of transformers. In case of my setup and CSS processing, the pipeline consists of the Less processor and clean-css. Metalsmith does all processing in-memory, it does not materialize the intermediate results (*.less transformed to *.css) to the file system. For this reason, the current approach to import inlining won't work -- the files being imported are not there physically on the disk. Since the content of Less transformed to CSS is available in memory, to make import inlining work, the imports would have to be resolved based on the paths and CSS contents provided in the hash input data (obviously, the caller would have to pass entries containing path and content of each imported CSS). |
Why: * When a hash is given as a source, some imports can be inlined in-memory taking styles from the hash.
Why: * when using a hash as an input, the sources it references should be processed lazily instead of a whole hash being serialized & tokenized eagerly. This change addresses the need by: * See #791 - in-memory imports require such lazy processing. The other way, we end up with duplicated rules, and have to rely on advanced processing to remove them.
Why: * when using a hash as an input, the sources it references should be processed lazily instead of a whole hash being serialized & tokenized eagerly. This change addresses the need by: * See #791 - in-memory imports require such lazy processing. The other way, we end up with duplicated rules, and have to rely on advanced processing to remove them.
It's ready on master now and due in 4.0 release. Thanks @stanislawosinski for the idea! |
Thanks @jakubpawlowicz! I'll give clean-css a try once version 4.0 is out. |
Stores all paths internally as normalized to *nix format but still outputs Windows friendly paths if needed. `source-map` does it internally so there's no need to transform paths in source maps.
I've been trying to get inlining of imports to work with
metalsmith-clean-css
, which passes the contents of the CSS files to clean as a hash:I've skimmed clean-css code very quickly and it appears that clean-css still tries to read the CSS text from the file system in this case. Shouldn't it instead use the contents provided in the data hash? In the specific case of metalsmith-clean-css, reading from the file system won't work because the files are not there -- all content is processed in-memory and flushed to disk once all processing is complete.
The text was updated successfully, but these errors were encountered: