-
Notifications
You must be signed in to change notification settings - Fork 220
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
On synchronous use and filtering styles #187
Comments
In the most basic implementation, I think that LESS and others could be handled in the methods that also use web-resource-inliner. The other method signatures are basically for content that is ready to be directly inlined from the Since it is really web-resource-inliner that is handling pulling in stylsheets and making all the transforms outside just inlining CSS, I think handling external LESS docs probably belongs on web-resource-inliner instead of directly on Juice. The process of pulling in those resources happens in web-resource-inliner, juice doesn't look at particular external resources itself. The processing/filtering of non-css A plugin architecture seems like an appropriate solution for attaching processors to files that are being pulled in and for transforming |
I understand the difference between sync and async methods in what would be inlined. The difficulty in implementing it in juice was that Doing it in web-resource-inliner (WRI) would be alright. The access to file context is better there. It would be a little disappointing not being able to The caveat is that there's a messy level of difficulty in doing it in WRI. Juice uses cheerio and so passing off an attributes object to a filter function or plugin and then manipulating parts of the element is easy. But WRI uses regular expressions to "parse" out the tags that need to be modified and does string replacements. Either each of tag's attributes needs to be custom parsed in WRI so attribute data can be provided. Or WRI would need to be rewritten to use cheerio as well. |
I was more suggesting doing the processing of any LESS, etc. before anything gets to getStylesData, so that shouldn't need to change. So as an example transform pipeline: WRI -> LESS and other transfoms -> Juice inlining with get StylesData This assumes WRI will inline LESS which I don't remember at the moment, but would be a simple change if it doesn't. Using this approach, you could make a new npm module to handle the LESS and transforms, which could be useful on its own and would easily plug into Juice, similar to WRI. The 2nd stage could simply transform LESS or whatever in-place to CSS. Sorry about my earlier explanation being unclear. Do you think that would work? |
Yeah, that idea might work. |
On second pass of that idea. The transforms in that pipeline run after WRI has turned I actually ran into this exact problem in my workaround to this issue. My workaround was to run WRI myself, create my own cheerio document, do my processing on the nodes in that document, then juice.juiceDocument the cheerio document and return the html. But since WRI already inlined the To handle this need for context in that pipeline which of these options do you like?
|
Another option would be that WRI support transforming content in it's processing. That could maybe work by supplying a map of file types or content types to transforms. So, if WRI finds a *.less file or a tag with a type of So that pipeline would then be WRI [ run transforms internally ] -> Juice inlining with get StylesData That would have the benefit then of WRI doing more of what it should be doing, which is inlining content in-place into HTML docs, and Juice continuing to focus on taking CSS and inlining it into Some psuedo config for WRI might be like this, though this likely needs some more thought to get the details of this right. transforms: [
{
extensions: [ "less" ]
types: [ "text/less" ],
transforms: ( doc, done ) => require( "less" ).render( doc, (e, output) => done( e, output.css ) )
},
...
]
Is this something you'd considered or see problems with? Thanks for thinking through this with me. |
@dantman I was wondering if you are working on this. I've been thinking about a 2.0 to change some of the weird default values but if this was to require any breaking changes I'd like to fit them into the same release. |
@jrit No, I've been making due with my workaround. |
WRI has a linkTransform and scriptTransform on it now, which should be able to handle transforming LESS files and other such things. Hope that is enough to close this without really missing anything. |
One feature I've considered trying to embed in juice is the ability to filter and replace some of the style tags. For example taking all
<style type="text/less">
tags, compiling them with less, and updating the content and type of the tag. Or filtering css through PostCSS.Initially I thought it would be as simple as a patch like this. Which should work. But only for synchronous things, which is a problem since some notable css transpilers like less are async.
This brought up some more issues/points that merit discussion:
@import
in LESS that was included through a<link>
rather than an inline<style>
tag the transpiler should know the original filename. This can be fixed either with another internaldata-
tag or by doing the filtering in web-resource-inliner (however the latter would mean filters cannot be applied to<style>
tags, implementation would also be messier).Thoughts?
The text was updated successfully, but these errors were encountered: