-
Notifications
You must be signed in to change notification settings - Fork 5
Skip non-matching insert-css statements #3
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
Conversation
Current coverage is
|
This allows people to still use `require('insert-css')` in their code. if it doesn't match the expected format, it just won't be extracted from the javascript bundle.
cf4cbae
to
3951399
Compare
ooh, looks good to me. 😄 merged as fbb0963, @yoshuawuyts can we has publish? |
Actually wait a lil bit. I'm not sure this is desirable, as something cool about @ajoslin you mentioned errors occurred? Could you explain what was going wrong? @joshwnj I know you were thinking of using this for I def like the implementation and idea, but just being cautious that we won't have to revert this change down the line |
@yoshuawuyts My specific use-case is inserting a base64 font that I The current errors, however, occur with anything that simply requires and calls insert-css on separate lines: var insertCss = require('insert-css')
insertCss('.foo { color: red }') The current parsing only works for the case of a require and its usage inline: require('insert-css')('.foo { color: red }') With the current ast-parsing logic, there's no way to cover every case (eg we can't cover insertCss being passed into a function in a different file). but I think that's OK. We could definitely improve the logic to know how to read these non-inline cases. Similar to brfs, we don't need to cover everything. I'm not very familiar with ast parsing, so I don't know how reliable I would be at expanding the logic here. |
@yoshuawuyts I don't think this patch will complicate things for me - cheers |
ah. hmm, could we use static-module here? |
Yes, static module is exactly what we need here! That makes things extremely simple. The css-extract plugin can just add a static-module transform for insert-css to the bundle. The only confusion here would be that dynamic uses of insert-css won't get found by static-module. But I think that's OK if we document it. I'll open a PR when I can. I say we close this for now in favor of a much better static-module implementation. |
reverts commit fbb0963 in favor of #3 (comment).
This allows people to still use
require('insert-css')
in their code.If it doesn't match the expected format, it just won't be extracted from the javascript bundle.
Before, non-matching
insert-css
statements caused an error.