-
Notifications
You must be signed in to change notification settings - Fork 47
Don't define transform as global #31
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
Global transforms run after all other transforms, which means that all other transforms will try to process the CSS file. This is bad for most transforms like e.g. brfs, which don't check whether the file is JS before proceeding This also makes https://github.com/css-modules/browserify-demo/ work
Thanks for the PR @spion . I added the Perhaps there's a different way to go about it? Regarding |
@joshwnj I see - that should work. I wonder if it would be possible to support pre-compiled CSS modules though. AFAIK one of the assumptions for npm modules is that they're distributed as pre-compiled (thats why browserify transforms aren't normally run on them). |
I'm not sure if I understand but the imported package can have a browser field in |
@spion & @serapath pre-compiling is a good idea and it would be great to explore this space. But since CSS Modules is not tied to browserify in any way I'm not sure we would want to require authors to include a browserify transform in their Using a global transform seemed to be the quick easy way to do this, but I'm aware there are maybe some unwanted side-effects :) If you take a look at the unit tests (and specifically, the one which fails with this PR) you'll see what I'm aiming for. Maybe there's a better way to reach that without using a global transform? |
@joshwnj it would not necessarily be tied to browserify. The way I imagine it, there would be:
Step (2) would only really be necessary when bundling the final app, while step (1) would be done by module authors when publishing their module (e.g. on npm) The way this will work in other bundlers (webpack/jspm) would be by detection: if the CSS file is a JS file, its considered precompiled; otherwise, it hasn't yet been compiled. (Alternatively, the existence of a corresponding This is all a rough and sketchy idea which doesn't necessarily blend ideally into css-modules, but its the best I've got :) Given that browserify is built on the premise that a transform's output is always JS, I'm not sure if its possible to come up with something that would work elegantly across browserify, webpack and jspm... |
hi folks – I'm just digging into this. looks like the folderify module has this same issue. |
Hi @spion, closing this now as in 0.16.0 (#64) the transform is not global unless you opt into that: https://github.com/css-modules/css-modulesify/blob/master/index.js#L96 Please let me know if it's still an issue |
Global transforms run after all other transforms, which means that all other transforms will try to process the CSS file.
This is bad for many transforms that are like e.g. brfs, which don't check whether the file is valid JS before proceeding to try and parse it (with acorn)
This patch makes https://github.com/css-modules/browserify-demo/ work