-
Notifications
You must be signed in to change notification settings - Fork 31
Make postcss-brunch both compiler and optimizer #33
Conversation
Doesn't this mean that PostCSS is run twice for .css files? |
No it is run only once. |
Would you mind explaining how that works? I think it is important for people to understand their build tools. |
Actually, while it runs only once on each CSS file, it also run on the assembled css file (optimize), so in fact it will run twice on the same CSS code, yeah. I just noticed that it was the case before: #2 Having both works with brunch 2.9, I think this plugin should really use only optimize, but it was changed back and forth by @paulmillr but it's unclear why. I thought having both functions would make things working without breaking stuff. But, as I wrote here brunch/sass-brunch#125 I think we should write a test suite that run sass, postcss, autoprefixer/cssnext... to ensure all those plugins play nicely. |
I don't like this. We need a more generic api which is built into Brunch for stuff which is reused my many plugins. |
I don't like it either, but we need to fix this without breaking stuff. What do you recommend? |
Don't know. Maybe let's get into discussing the new API ASAP. I was thinking that postcss could pass This way stuff from sass, etc would be passed through without parsing the output twice. |
But what is wrong with droping compile() and have postcss only as an optimizer? |
I don't remember the exact reason but we've dropped this decision because it broke something. |
#24 contains some information on the drawbacks (in some case) on using this as an optimizer. |
Ok, I get what the whole "optimizer" problem is. The real solution is to allow compiler chaining I guess. |
I did a bit of digging, and this is getting more and more complicated. We need a way to compile a file, and if it produces a file with an extension another compiler support, that other compiler should be called (with a check to avoid cycling). While I was able to chain compilers, I was unable to generate a proper source map. |
I'd like to help move this issue forward. Chaining compilers sounds like an intuitive solution to this. @kuon, can you share your attempt at chaining so we can work on merging it into Brunch? In an effort to get this package to work with sass-brunch, I branched it off the last version that worked with sass-brunch as suggested here, then added a quick fix to pass the source map along. See here. Does that help? |
I tried to work a bit on this issue on the brunch source code: But I realised I needed a distinct step, thus brunch/brunch#1565 I currently got a bit tired of this issue and switched to webpack. |
I've implemented chaining in brunch/brunch#1571. All we need is to release current masters of preprocessors and add |
@shvaikalesh great! I'd like to keep using brunch as webpack is a bit over engineered, but I was on a tight schedule. I hope this will get it fixed. |
Fixes brunch#124. Fixes brunch/postcss-brunch#31. Closes brunch/postcss-brunch#33. Fixes brunch/brunch#1619.
I'm using sass-brunch with postcss-brunch and autoprefixer on one of my projects. I've upgraded to the latest brunch (2.10.6) and sass-brunch (2.10.2), but the latest postcss-brunch (2.0.5) breaks autoprefixing (I'm currently using @jacksonrayhamilton's patched version of postcss-brunch, which restores autoprefixing for me; see https://github.com/jacksonrayhamilton/postcss-brunch/tree/sass-support-and-sourcemap-fix). I also noticed that this particular issue was closed because brunch/sass-brunch#135 was merged in, except that the required postcss-brunch changes (mentioned in the PR's HOWEVER note) have not yet made it into @paulmillr @shvaikalesh I'd really love to get autoprefixing working again, and I'm willing to help however I can, so what's the current status of all this? Thanks, |
@caleb531 the only thing different in 2.10.2 is newer version of node-sass. It would be great to have the problem traced back to the project. Otherwise it's unwise to change |
@paulmillr @shvaikalesh FWIW: I can confirm that adding an I've ready through #24 and I respect the rationale for keeping postcss-brunch as a compiler instead of an optimizer. I agree that breaking things like CSS modules for the purpose of enabling support for preprocessors (like sass-brunch) is not a fair compromise. However, I'm still really wanting to see postcss-brunch play nicely with preprocessor plugins (as I really don't like referencing a patched version of this package for new Brunch projects). Allow me to throw out a few ideas:
Thoughts? |
@caleb531 The real fix is to add |
@lydell thanks for the clarification. I tried adding diff --git a/index.js b/index.js
index 6c49ab4..bfe011b 100644
--- a/index.js
+++ b/index.js
@@ -60,7 +60,7 @@ class PostCSSCompiler {
file.data = '';
}
if (file.map) {
- opts.map.prev = file.map.toJSON();
+ opts.map.prev = file.map.toJSON ? file.map.toJSON() : file.map;
}
return this.processor.process(file.data, opts).then(result => { With both the above check in postcss-brunch and the addition of |
@lydell On second thought, I realize that the proposed For anyone trying to make sense of this tangled web of issues, here's what needs to happen (as I understand it) to get postcss-brunch working properly:
|
Thanks for the writeup @caleb531 ! I'm trying to race this around and get postcss, brunch and sass to play nicely with each other... apparently that's a super hard task. I'll try to check out the fork you mentioned although that's less than ideal... might be I'll see if I have more success moving it all to webpack (for reasons I really NEED autoprefixer, in case someone understands this wrong: ❤️ to all maintainers and thanks for all your work :) ) |
If you get here, as mentioned earlier by @caleb531 the fork in the dependencies as follows works for me:
|
@PragTob Yes, that fork works, but it's based on an older version of postcss-brunch. If you'd like to patch autoprefixer for the most recent versions of postcss-brunch and sass-brunch, see my newly-created forks: https://github.com/caleb531/sass-brunch I applied exactly the same changes I described above (the |
Well, this issue has become somewhat more complicated. Apparently, the latest commit in sass-brunch (brunch/sass-brunch@7ffb2e6) has rendered the plugin unable to load (see the sass-brunch issue I just created). Needless to say, I needed to revert this commit in my fork (in addition to committing my aforementioned EDIT: The aforementioned sass-brunch issue is actually a bug in brunch core, for which there is already a pull request. As on now, that pull request has been merged into master, with a new brunch release coming later today. :) |
Sadly, the forks with their respective latest latest versions don't seem to invoke auroprefixer so I'm back tot he old fork for now :| |
@PragTob Don't fret! Perhaps you missed my revised comment above, but in short, try my forks with brunch 2.10.9 (released yesterday), which fixes a bug that was preventing sass-brunch from loading. I just tried it on one of my Brunch projects, and autoprefixer totally works for me. "devDependencies": {
"brunch": "^2.10.9",
"postcss-brunch": "github:caleb531/postcss-brunch",
"sass-brunch": "github:caleb531/sass-brunch"
} |
@caleb531 ah dang... I read the comment, but before the edit and when I got back here didn't read it again - will try it again - thanks :D |
Once again, this issue has gotten more complicated. I discovered today that the switch from optimizer to compiler for postcss-brunch breaks the watching of sass partials by sass-brunch. That is, when I make a change to a sass partial (e.g. I've created a test project to demonstrate this. After running
Here's the full source code if you want to try it yourself: Regardless, because I only ever use a preprocessor (like sass-brunch) with postcss-brunch, I'm updating my fork to make postcss-brunch an optimizer again until we find an acceptable solution to this particular bug. @paulmillr or @shvaikalesh: What do you make of this? Should I open up a separate issue? (and if so, for which project?) |
Hey Caleb. Greatly appreciate the report: indeed, |
@shvaikalesh: Just checking in—any updates on resolving the dependency-merging bug? Is there an existing GitHub issue I can subscribe to? (for that particular bug) Oh, and thanks for all of the work you do on Brunch! :) |
This PR will fix things as soon it is competed and merged. |
Fix #31 and stay consistent.