We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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 is not working with SCSS modules.
I have an application with ComponentA and ComponentB using classA, but not classB.
ComponentA
ComponentB
classA
classB
// ComponentA import React from "react"; import styles from "./styles.module.scss"; export function ComponentA() { return <div className={styles.classA}>ComponentA</div>; }
// ComponentB import React from "react"; import styles from "./styles.module.scss"; export function ComponentB() { return <div className={styles.classA}>ComponentB</div>; }
// styles.module.scss .classA { color: green; } .classB { color: purple; }
I have sideEffects: true in my package.json and the following webpack configuration:
sideEffects: true
/* eslint-env node */ const path = require("path"); const HtmlWebpackPlugin = require("html-webpack-plugin"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); module.exports = { mode: "production", entry: { index: path.resolve(__dirname, "./src/index.tsx"), }, output: { path: path.resolve(__dirname, "dist"), filename: "[name].bundle.js", }, resolve: { extensions: [".ts", ".tsx", ".js", ".jsx", ".scss", ".css"], }, module: { rules: [ { test: /\.m?js/u, resolve: { fullySpecified: false, }, }, { test: /\.tsx?$/u, use: "ts-loader", }, { test: /\.s[ac]ss$/u, use: [ { loader: MiniCssExtractPlugin.loader, options: { esModule: true, }, }, { loader: "css-loader", options: { esModule: true, modules: { namedExport: true, }, }, }, "sass-loader", ], }, { test: /\.css$/u, use: [MiniCssExtractPlugin.loader, "css-loader"], }, ], }, plugins: [ new HtmlWebpackPlugin({ template: path.resolve(__dirname, "src/index.html"), }), new MiniCssExtractPlugin(), ], };
After building, css for classB exists in bundled CSS:
// dist/index.css .lbEYKkO5_LPzVhlhmgOW{color:green}.HrcP_c2cJ59oMgw7mdme{color:purple}
After building, css for classB would not exist in bundled CSS:
// dist/index.css .lbEYKkO5_LPzVhlhmgOW{color:green}
https://github.com/jordanjlatimer/css-modules-css-loader-tree-shaking
npx webpack-cli info
System: OS: macOS 12.6.8 CPU: (4) x64 Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz Memory: 285.48 MB / 8.00 GB Binaries: Node: 16.6.2 - ~/.nvm/versions/node/v16.6.2/bin/node npm: 7.20.3 - ~/.nvm/versions/node/v16.6.2/bin/npm Browsers: Chrome: 117.0.5938.149 Safari: 16.6 Packages: css-loader: ^6.8.1 => 6.8.1 html-webpack-plugin: ^5.5.3 => 5.5.3 sass-loader: ^13.3.2 => 13.3.2 ts-loader: ^9.5.0 => 9.5.0 webpack: ^5.88.2 => 5.88.2 webpack-cli: ^5.1.4 => 5.1.4
The text was updated successfully, but these errors were encountered:
Sorry, tree shaking for CSS is not supported right now - #506
Sorry, something went wrong.
No branches or pull requests
Bug report
Tree shaking is not working with SCSS modules.
I have an application with
ComponentA
andComponentB
usingclassA
, but notclassB
.I have
sideEffects: true
in my package.json and the following webpack configuration:Actual Behavior
After building, css for
classB
exists in bundled CSS:Expected Behavior
After building, css for
classB
would not exist in bundled CSS:How Do We Reproduce?
https://github.com/jordanjlatimer/css-modules-css-loader-tree-shaking
Please paste the results of
npx webpack-cli info
here, and mention other relevant informationSystem:
OS: macOS 12.6.8
CPU: (4) x64 Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz
Memory: 285.48 MB / 8.00 GB
Binaries:
Node: 16.6.2 - ~/.nvm/versions/node/v16.6.2/bin/node
npm: 7.20.3 - ~/.nvm/versions/node/v16.6.2/bin/npm
Browsers:
Chrome: 117.0.5938.149
Safari: 16.6
Packages:
css-loader: ^6.8.1 => 6.8.1
html-webpack-plugin: ^5.5.3 => 5.5.3
sass-loader: ^13.3.2 => 13.3.2
ts-loader: ^9.5.0 => 9.5.0
webpack: ^5.88.2 => 5.88.2
webpack-cli: ^5.1.4 => 5.1.4
The text was updated successfully, but these errors were encountered: