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
CSS modules: remove unused classes #5363
Conversation
This pull request has been linked to and will mark 1 task as "Done" when merged:
|
95a8834
to
072ab5b
Compare
Benchmark ResultsKitchen Sink ✅
Timings
Cold Bundles
Cached Bundles
React HackerNews ✅
Timings
Cold Bundles
Cached Bundles
AtlasKit Editor ✅
Timings
Cold Bundles
Cached Bundles
Three.js ✅
Timings
Cold BundlesNo bundle changes detected. Cached BundlesNo bundle changes detected. |
bd43503
to
3fb781d
Compare
8fea0fd
to
cae5b33
Compare
@@ -36,8 +36,8 @@ | |||
"parcel-bundler": "2.0.0-beta.1", | |||
"parcel": "2.0.0-beta.1", | |||
"postcss-custom-properties": "^8.0.9", | |||
"postcss-import": "^12.0.1", | |||
"postcss": "^8.0.0", | |||
"postcss-import": "^13.0.0", |
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.
One interesting situation that I ran into was that the old postcss-import version didn't use PostCSS 8 and inserted nodes into the AST that were missing some methods from recent my PostCSS PR (toJSON
). This caused a build error
cae5b33
to
b7fde05
Compare
[...asset.symbols].map(([, {local}]) => `.${local}`), | ||
); | ||
let usedLocalSymbols = | ||
// we have to still support the more common default imports |
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.
Wonder if we should add a warning here so people know to switch from default imports to namespaces?
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 warning would be nice, but at this point, there is no way to differentiate a default import from this case:
import * as styles from "..."
console.log(styles.default);
Which also means that calling a class default
means no class gets shaken....
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.
Can we add some kind of metadata to the dependency to mark this? I think a lot of projects might not see any benefit from this because they use default imports...
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.
b7fde05
to
00af5ea
Compare
00af5ea
to
0572d04
Compare
0572d04
to
4c693b0
Compare
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.
🎉🎉🎉
(asset.value.env.scopeHoist && asset.value.type === 'js') || | ||
(this.options.mode === 'production' && | ||
asset.value.type === 'css' && | ||
asset.value.symbols) |
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.
😬
let loc = defaultImport.symbols.get('default')?.loc; | ||
logger.warn({ | ||
message: | ||
'CSS modules cannot be tree shaken when imported with a default specifier', |
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.
We could get rid of this limitation if we tracked member accesses of default/named imports like we were just discussing 😉
Depends on #5362Waiting for postcss/postcss#1484Closes T-783
Example usage (this has to be a namespace import, not a default import!):