[postcss-preset-env] ability to inject js polyfill #228
Replies: 5 comments
-
Hi @fchastanet There was a request for this here : #110 (comment) My main concern with providing something for this is that there are so many javascript tools. We can't support each but if we support one we will end up supporting all of them eventually. Would it help if we have a plugin option that takes a callback? const postcss = require('postcss');
const postcssPresetEnv = require('postcss-preset-env');
const neededJSPolyfills = [];
postcss([
postcssPresetEnv({
didTransformCSS: (plugin) => {
console.log(`plugin ${plugin} did run and transformed CSS`);
if (plugin === 'blank-pseudo-class') {
neededJSPolyfills.push('css-blank-pseudo/browser');
}
}
})
]).process(YOUR_CSS /*, processOptions */); This callback is not specific to your use case but does expose the information you would need to dynamically inject the JS polyfills. At this time even the example above is not possible to provide quickly. |
Beta Was this translation helpful? Give feedback.
-
Hello @romainmenke |
Beta Was this translation helpful? Give feedback.
-
In the upcoming
The extra feature of such a callback would be that it would only trigger when the plugin actually does something. Making it generic is more interesting as anyone could then build things on top of it for their need. If a plugin for example changes or is dropped (dead spec) then users might use it to find source code that depends on it. |
Beta Was this translation helpful? Give feedback.
-
Maybe propose an interface that the plugin has to implement in order to be automatically installed by your tool. |
Beta Was this translation helpful? Give feedback.
-
Definitely an option, but it might be confusing to users if some plugins support this and other don't. They would expect it to just always work :) I suggest we convert this issue to an open discussion and invite others to give feedback on the API proposal or give more insights in their needs. |
Beta Was this translation helpful? Give feedback.
-
What would you want to propose?
Hello,
Maybe I misconfigured the tool but I don't see a possibility to inject js polyfill automatically
Suggested solution
as it would imply to add node modules and injection not pilotable from postcss I guess, maybe a solution would be to suggest installation of the missing node modules resulting on exit code != 0 if node module is not installed but feature used
Additional context
I''ve made a POC for Vuejs using Vite and integrating this tool
but js files have to be integrated manually
github.com/fchastanet/template_frontend_vue_vite
Validations
Would you like to open a PR for this feature?
Beta Was this translation helpful? Give feedback.
All reactions