-
Notifications
You must be signed in to change notification settings - Fork 34
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
Question / feature request: use processor
to generate CSS modules
#173
Comments
Hey @marcalexiei - From what you're proposing it seems you're trying to export the CSS in question as a "named export", is that correct? |
.. essentially, if you could elaborate on the use cases, it would help clarify what we need in this case. |
The use case is to allow the plugin to emit CSS modules. |
Ok - Question 2. - Doesn't rollup already have rollup css-module plugins? E.g., |
Also, seems something like a |
There are rollup-plugin-postcss and rollup-plugin-postcss-modules They are both un-mainted.
It would be fine, however I was thinking about using
rollup-plugin-sass/src/utils/processRenderResponse.ts Lines 61 to 74 in 3008e00
My proposed solution is about to add the required logic around this code. |
Ok, I see - Makes sense. In this case please feel free to move ahead with opening a PR. |
This feature is really needed. |
Hi @elycruz, due to the urgent need for this feature, I've implemented it through a patch and have already put it into use. This was achieved by adding a specific field to the return value of the processor (similar to diff --git a/dist/index.js b/dist/index.js
index 8cd7f0a3043f0f6912c03358f500d008b1193504..ba21a04e5190fcdac79fc8f0a64ef7ee0c99e5bd 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -81,9 +81,9 @@ const processRenderResponse = (rollupOptions, file, state, inCss) => {
const outCss = result.css;
delete result.css;
const restExports = Object.keys(result).reduce((agg, name) => agg + `export const ${name} = ${JSON.stringify(result[name])};\n`, '');
- return [outCss, restExports];
+ return [outCss, restExports, result.cssModules];
})
- .then(([resolvedCss, restExports]) => {
+ .then(([resolvedCss, restExports, cssModules]) => {
const { styleMaps } = state;
styleMaps[file].content = resolvedCss;
const out = JSON.stringify(resolvedCss);
@@ -96,6 +96,9 @@ const processRenderResponse = (rollupOptions, file, state, inCss) => {
else if (!rollupOptions.output) {
defaultExport = out;
}
+ if (cssModules) {
+ defaultExport = JSON.stringify(cssModules)
+ }
return `${imports}export default ${defaultExport};\n${restExports}`;
}));
};
|
I realize that the current official version prevents me from generating CSS modules because the processor cannot return a default export. So I think perhaps allowing a default export here could solve many problems. |
From my point of view your patch might introduce some bugs:
To wrap up I don't think that this solution is feasible when using rollup If you want to open a PR you should consider these scenarios, otherwise you have to wait for a few days... |
Followup of #166 (comment)
I would like to do another change before the next release:
I'm trying to use
processor
to generate CSS modules:Right now the plugin always returns the css string as
export default
and I haven't found a clean solution to change it that usingprocessor
option.Have you implemented something similar that I can use or do you know another way?
My possible solution is to allow user to include a new property inside
processor
output (e.g.:cssModuleMap
)which, if present, will be used as
default
export.What do you think?
The text was updated successfully, but these errors were encountered: