-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Tree Shaking #98
Comments
see rollup-plugin-purifycss maybe this can help |
I am currently trying to get this working, purgecss looks superior: |
I just published a module which enables this (works for inlined CSS only). I'm glad for any feedback: https://github.com/dferber90/rollup-plugin-postcss-treeshakeable |
We could make this functionality part of The gist of it is that instead of outputting var css = ".foo { background: red; }";
export default { foo: "foo__classname_1 " };
import styleInject from "<some-folder>/style-inject/dist/style-inject.es.js";
styleInject(css); which calls import styleInject from "<some-folder>/style-inject/dist/style-inject.es.js";
var cssMap = { foo: "foo__classname_1 " };
var hasRun;
var styles = function styles() {
if (!hasRun) {
hasRun = true;
styleInject(".foo { background: red; }");
}
return cssMap;
};
export default styles; This enables treeshaking. It has the downside that any styles are only applied when the component is actually rendered. All consumers have to be changed to use the functional export instead import styles from "./Butler.mod.css";
-const Butler = props => <div className={styles.alfred}>I am Butler</div>;
+const Butler = props => <div className={styles().alfred}>I am Butler</div>; I tried emitting a module which uses a proxy or getters instead. This would have meant that we can keep the same export. But both approaches were not picked up by treeshaking/dead code elimination unfortunately. See the example for a walkthrough of how it works. Sidenote: Update: I now created the missing piece: https://github.com/dferber90/style-loader-treeshakeable |
+1 |
Probably not the greatest solution in the world, but i wonder if simply using commonjs |
If there are 2 components which both import their respective css files which are imported in an
index.js
and exported out. Then in another module only one of them is imported, both css files are added to the extracted CSS file. The JS said of it tree shakes the component not being used, but that is not the case of the CSS.Is there a way to exclude CSS imports that are not being used by the solution?
The text was updated successfully, but these errors were encountered: