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
Add postprocess plugin set #60
Add postprocess plugin set #60
Conversation
I probably won't have a chance to look at this deeply until this weekend, but thank you so much for taking this on! |
No problem 😄 we're just using my fork in our app right now and I can confirm it works as intended. I'm excited to get this finished and published, we've been using a fork of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple questions, but overall this is looking great — let me know if there's anything I can do to help out on the testing front.
lib/output-styles-preprocessor.js
Outdated
@@ -24,8 +25,17 @@ OutputStylesPreprocessor.prototype.toTree = function(inputNode, inputPath, outpu | |||
|
|||
debug('concatenating module stylesheets: %o', concatOptions); | |||
|
|||
var parentOptions = options.registry.app.options || {}; | |||
var cssModulesOptions = parentOptions.cssModules || {}; | |||
var postprocessPlugins = cssModulesOptions.plugins && cssModulesOptions.plugins.postprocess; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call this.owner.getPlugins()
to simplify this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh awesome, I'll update that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dfreeman was this API removed between the initial PR and now? That method doesn't exist anymore
edit would the right thing now be getPostcssPlugins
? That seems to do what I'm looking for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's right—IIRC that was renamed to distinguish between ECM plugins and PostCSS plugins
lib/postcss-persistent-filter.js
Outdated
map: { | ||
inline: false, | ||
annotation: false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this play nicely with user-specified source map settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure -- @jasonmit ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure what is meant by user specific map settings, these: https://ember-cli.com/asset-compilation#source-maps ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, we read that config and pass it along to broccoli-css-modules
(as well as using it when concatenating everything together)
package.json
Outdated
@@ -24,6 +24,7 @@ | |||
}, | |||
"homepage": "https://github.com/salsify/ember-css-modules#readme", | |||
"devDependencies": { | |||
"broccoli-persistent-filter": "^1.2.11", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in dependencies
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, probably. @jasonmit ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, should be moved
Sorry this got away from me @dfreeman. If you know of a good way to do the smoke test for the |
This is intended only for short term use / testing. Will be unnecessary once salsify#60 and broccoli-css-modules#4 are merged
I hope this will be merged eventually. Very useful. |
Yeah, sorry about that. getting back to the tests just hasn't been a priority but should be. It won't be this weekend, but maybe the weekend after I'll be able to carve out some time |
Any updates on this? |
Yeah, so... No. But I really need to do this, since our app requires this PR and we'd really like to get on the official release (and PostCSS 6). My holdup is mostly just not really knowing how to test Broccoli stuff. Maybe @jasonmit has some insight there? |
For testing Broccoli stuff I've found broccoli-fixture to be super helpful — we use it over in |
Cool, I'll definitely check into that. First step is rebasing, since it's been so long since this PR was made 😅 but it's on my list to check this out this weekend since we really want to get our app off of PostCSS 5 and onto 6. |
@dfreeman after checking out the new Plugin system you have added since this PR started (which is awesome, by the way!) I think this could actually be added as a plugin instead. Would you prefer that to adding it to the default add-on? I feel like the use-cases for this are actually pretty slim, and like the idea of allowing people to opt in to running the code by installing an additional add-on. I think it could look a lot like the Sass plugin, just running arbitrary PostCSS plugins that the user can configure instead of enabling Sass. edit after looking more... maybe that's not the right approach. I'm going to keep working on this as a PR. |
@alexlafroscia I think framing this as a plugin is an interesting idea — as it sounds like you've discovered, the current plugin API is lacking the hook you'd need, but I could easily imagine adding broccoli-based plugin methods for manipulating the tree pre-CSS-modules, post-CSS-modules and post-concatenation. Your plugin would just implement that third hook, taking the concatenated file and performing an additional round of PostCSS processing on it. What do you think of an approach like that? |
db3ca50
to
8f45c3c
Compare
Yeah, that sounds interesting! I'm fine doing it that way. My first commit here (I squashed all the previous commits together to make it easier to rebase onto |
Given how lightweight this wound up being, I'm not opposed to landing it as core functionality, as long as we can get some kind of smoke test in place in one of the dummy app/addons to prevent regressions. Regardless, it does feel like plugins should be able to implement something like this, but I can save tackling that for another day :) |
Working on that test now :) Just trying to look through the existing tests to get an idea of how I can verify that the |
@dfreeman what would you be looking for for a "smoke test" here? I'm not sure how to verify that those plugins were run other than setting up a dummy app with a plugin and checking to see if the output CSS was transformed. Would that do? Maybe using |
I think the simplest thing to do would be to add a component to the dummy app whose |
👍 great idea. I'll do that! |
I made a PR there that enables the same style of plugin definition that the `before` and `after` hooks support to make `postprocess` consistent with them. This bumps the version of the dependency to include that change.
No idea if I did that right... I'm on a new laptop and was having trouble getting the tests running locally. I'm going to let CI tell me if that worked. |
1817a6b
to
556bea0
Compare
556bea0
to
0aad226
Compare
@dfreeman just wanted to bump this... we'd love to get off of my old fork and onto the latest version, but we need this to land first! |
Oops, sorry for the delay @alexlafroscia! I meant to look at this before I left for vacation and totally lost track. I should have some time in the next day or so to take a look. |
No problem! Thanks for merging, glad to get this landed after so long (my fault, not yours) 😅 |
This is now released in 0.7.3 — thanks again @alexlafroscia! 🎉 |
Adds a new option to provide a set of PostCSS plugins to run after concatenation has taken place. This is useful for plugins like
postcss-sprites
, which should be run later in the CSS pipeline.Closes salsify/broccoli-css-modules#3
Todo
Unit tests for the new Broccoli pluginreplaced by a dependencymaster
postprocess
plugins are applied to the output file.