Skip to content
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

Merged
merged 11 commits into from Jan 2, 2021
Merged

CSS modules: remove unused classes #5363

merged 11 commits into from Jan 2, 2021

Conversation

mischnic
Copy link
Member

@mischnic mischnic commented Nov 18, 2020

Depends on #5362
Waiting for postcss/postcss#1484

Closes T-783

Example usage (this has to be a namespace import, not a default import!):

import * as styles from "./style.module.css";

console.log(styles["b-2"]);

@height
Copy link

height bot commented Nov 18, 2020

This pull request has been linked to and will mark 1 task as "Done" when merged:

💡Tip: You can link multiple Height tasks to a pull request.

Base automatically changed from symbols-static-namespace-import to v2 November 19, 2020 13:38
@parcel-benchmark
Copy link

parcel-benchmark commented Nov 19, 2020

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 4.17s -26.00ms
Cached 744.00ms -32.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.d5807e82.webp 102.94kb +0.00b 65.00ms +10.00ms ⚠️
dist/modern/parcel.d5807e82.webp 102.94kb +0.00b 42.00ms -12.00ms 🚀
dist/legacy/index.5acd07fb.js 1.07kb +0.00b 1.44s -87.00ms 🚀
dist/modern/index.110a671b.js 1.07kb +0.00b 1.43s +94.00ms ⚠️
dist/legacy/index.html 701.00b +0.00b 1.44s -87.00ms 🚀
dist/modern/index.html 701.00b +0.00b 1.44s +102.00ms ⚠️
dist/legacy/index.5859ab37.css 77.00b +0.00b 1.44s -87.00ms 🚀
dist/modern/index.77ce15d4.css 77.00b +0.00b 1.44s +102.00ms ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.d5807e82.webp 102.94kb +0.00b 58.00ms -23.00ms 🚀
dist/modern/parcel.d5807e82.webp 102.94kb +0.00b 76.00ms +20.00ms ⚠️
dist/legacy/index.5acd07fb.js 1.07kb +0.00b 84.00ms -6.00ms 🚀
dist/legacy/index.html 701.00b +0.00b 58.00ms -31.00ms 🚀
dist/legacy/index.5859ab37.css 77.00b +0.00b 58.00ms -30.00ms 🚀

React HackerNews ✅

Timings

Description Time Difference
Cold 23.04s +12.00ms
Cached 14.12s -139.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/logo.24c8bf9e.png 274.00b +0.00b 51.00ms -19.00ms 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/index.js 479.93kb +0.00b 84.00ms -6.00ms 🚀
dist/PermalinkedComment.52a3fc6f.js 4.22kb +0.00b 84.00ms -5.00ms 🚀
dist/UserProfile.42c44c22.js 1.70kb +0.00b 84.00ms -5.00ms 🚀
dist/NotFound.984005f8.js 532.00b +0.00b 69.00ms +13.00ms ⚠️

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 2.13m +1.85s
Cached 2.93s -183.00ms 🚀

Cold Bundles

Bundle Size Difference Time Difference
dist/index.152dbfb8.js 2.34mb -3.00b 🚀 1.26m +45.00ms
dist/pdfRenderer.f8527c1c.js 1.11mb +0.00b 41.96s -2.16s 🚀
dist/popup.c7d523d4.js 169.35kb +0.00b 1.26m +51.04s ⚠️
dist/EmojiPickerComponent.13c2889c.js 139.08kb +0.00b 9.92s -961.00ms 🚀
dist/Toolbar.86dd17ff.js 99.25kb +0.00b 44.26s -2.67s 🚀
dist/media-viewer.022fdde3.js 72.71kb +0.00b 12.23s -1.51s 🚀
dist/card.f3741dfa.js 53.76kb +0.00b 10.32s -1.09m 🚀
dist/card.2fa3ec33.js 51.51kb +0.00b 22.67s -53.16s 🚀
dist/Modal.34634fc9.js 39.03kb +0.00b 3.78s -1.48s 🚀
dist/component.088d2ae3.js 30.87kb +0.00b 3.77s +1.51s ⚠️
dist/esm.2811a427.js 27.71kb +0.00b 9.90s -983.00ms 🚀
dist/component.22035ce4.js 22.40kb +0.00b 3.78s -1.49s 🚀
dist/DatePicker.a992c084.js 21.16kb +0.00b 9.89s -925.00ms 🚀
dist/smartMediaEditor.cfe1bdad.js 16.79kb +0.00b 42.98s -2.71s 🚀
dist/js.0a808d22.js 16.55kb +0.00b 3.78s -1.48s 🚀
dist/dropzone.374e8cb6.js 16.03kb +0.00b 13.10s -30.89s 🚀
dist/ui.078d3b2e.js 14.11kb +0.00b 10.26s -1.09m 🚀
dist/workerHasher.83104f73.js 11.90kb +0.00b 7.53s -1.14s 🚀
dist/media-viewer.083ce2a1.js 4.01kb +0.00b 12.24s -1.87s 🚀
dist/EmojiPickerComponent.9a5c1b76.js 3.68kb +0.00b 7.60s -28.81s 🚀
dist/png-chunks-extract.692b85d1.js 3.55kb +0.00b 3.78s -1.48s 🚀
dist/index.10f02a5e.css 3.46kb +0.00b 45.41s -2.64s 🚀
dist/dropzone.c5e4485d.js 3.44kb +0.00b 1.26m +50.84s ⚠️
dist/Modal.420db102.js 3.15kb +0.00b 985.00ms -1.40s 🚀
dist/clipboard.a67b66af.js 2.97kb +0.00b 13.59s -30.61s 🚀
dist/16.93e3596b.js 2.49kb +0.00b 985.00ms -1.26s 🚀
dist/ResourcedEmojiComponent.557284bd.js 2.15kb +0.00b 7.60s -4.84s 🚀
dist/card.09f4d8e9.js 2.15kb +0.00b 1.24m +58.91s ⚠️
dist/date.c50d5e8c.js 1.96kb +0.00b 4.65s -2.18s 🚀
dist/images.c0aa934a.js 1.90kb +0.00b 4.67s -1.17s 🚀
dist/feedback.0e55f851.js 1.86kb +0.00b 5.10s -3.48s 🚀
dist/16.8ab9c9cf.js 1.86kb +0.00b 4.15s -1.47s 🚀
dist/browser.dfefe24a.js 1.82kb +0.00b 22.66s -21.57s 🚀
dist/workerHasher.245b987a.js 1.75kb +0.00b 9.93s +1.26s ⚠️
dist/workerHasher.f5a304ed.js 1.75kb +0.00b 42.14s -2.20s 🚀
dist/list-number.41f28a70.js 1.68kb +0.00b 4.76s -1.08s 🚀
dist/status.eb15cda1.js 1.68kb +0.00b 4.96s -1.13s 🚀
dist/code.d63c0558.js 1.61kb +0.00b 4.54s -1.20s 🚀
dist/link.a9025e77.js 1.53kb +0.00b 4.76s -1.07s 🚀
dist/heading6.053111a7.js 1.53kb +0.00b 5.09s -1.14s 🚀
dist/heading3.9115aad6.js 1.51kb +0.00b 5.08s -1.11s 🚀
dist/16.b19b33ca.js 1.51kb +0.00b 3.97s -1.51s 🚀
dist/16.fe7e09db.js 1.46kb +0.00b 3.97s -1.51s 🚀
dist/emoji.d5ab3e45.js 1.45kb +0.00b 4.65s -1.18s 🚀
dist/16.7fc8af6d.js 1.45kb +0.00b 985.00ms -1.26s 🚀
dist/16.474c8276.js 1.44kb +0.00b 4.51s -1.22s 🚀
dist/16.d49a0bb7.js 1.40kb +0.00b 4.51s -1.22s 🚀
dist/heading5.731efbe4.js 1.40kb +0.00b 5.09s -1.11s 🚀
dist/16.c4941d0d.js 1.36kb +0.00b 4.15s -1.47s 🚀
dist/16.a4fa1a69.js 1.34kb +0.00b 985.00ms -1.26s 🚀
dist/heading2.de347970.js 1.33kb +0.00b 4.97s -1.22s 🚀
dist/16.ad29438e.js 1.32kb +0.00b 4.15s -1.47s 🚀
dist/16.3d7a389d.js 1.31kb +0.00b 4.51s -1.22s 🚀
dist/media-card-analytics-error-boundary.5ce95433.js 1.30kb +0.00b 10.31s -2.15s 🚀
dist/mention.1703453a.js 1.29kb +0.00b 4.76s -1.21s 🚀
dist/heading4.5089aec7.js 1.29kb +0.00b 5.09s -1.11s 🚀
dist/Modal.ae6f5f7a.js 1.28kb +0.00b 3.78s -1.48s 🚀
dist/16.55b14beb.js 1.27kb +0.00b 985.00ms -1.26s 🚀
dist/layout.32cc11b1.js 1.27kb +0.00b 4.76s -1.08s 🚀
dist/16.45835899.js 1.27kb +0.00b 4.15s -1.46s 🚀
dist/16.e83a0923.js 1.26kb +0.00b 3.97s -1.51s 🚀
dist/16.d315628f.js 1.26kb +0.00b 3.97s -1.51s 🚀
dist/16.cc8ae77e.js 1.26kb +0.00b 3.98s -1.52s 🚀
dist/divider.6cc4f21a.js 1.25kb +0.00b 4.65s -2.18s 🚀
dist/quote.b905d023.js 1.25kb +0.00b 4.96s -1.13s 🚀
dist/component.242a45f9.js 1.23kb +0.00b 3.73s +1.34s ⚠️
dist/action.3a733320.js 1.23kb +0.00b 4.51s -1.22s 🚀
dist/16.f1c68cda.js 1.23kb +0.00b 3.73s +1.34s ⚠️
dist/decision.1f5dd6ad.js 1.21kb +0.00b 4.65s -2.18s 🚀
dist/panel-warning.7dcb372a.js 1.21kb +0.00b 4.86s -1.21s 🚀
dist/16.8cd85281.js 1.18kb +0.00b 4.17s -1.45s 🚀
dist/list.7d80b06a.js 1.18kb +0.00b 4.76s -1.18s 🚀
dist/heading1.c1474f93.js 1.18kb +0.00b 4.96s -1.14s 🚀
dist/panel-error.4dcbeea1.js 1.11kb +0.00b 4.86s -1.11s 🚀
dist/panel.9407e91b.js 1.10kb +0.00b 4.87s -2.43s 🚀
dist/table.547bc9c1.js 1.09kb +0.00b 4.96s -1.13s 🚀
dist/media-picker-analytics-error-boundary.607a1e52.js 1.05kb +0.00b 1.26m +31.87s ⚠️
dist/panel-success.23208184.js 1.05kb +0.00b 4.86s -1.12s 🚀
dist/media-card-analytics-error-boundary.f92fc998.js 1.05kb +0.00b 10.31s -1.09m 🚀
dist/media-card-analytics-error-boundary.36e013e9.js 1.05kb +0.00b 41.97s -2.36s 🚀
dist/panel-note.7a985368.js 1.05kb +0.00b 4.86s -1.11s 🚀
dist/media-viewer-analytics-error-boundary.cceb3bd6.js 995.00b +0.00b 12.24s -3.33s 🚀
dist/simpleHasher.26a74474.js 755.00b +0.00b 7.53s -1.13s 🚀
dist/simpleHasher.042b95c1.js 755.00b +0.00b 42.23s -3.25s 🚀
dist/index.html 119.00b +0.00b 3.77s +502.00ms ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/Toolbar.7ab8152a.js 99.13kb +0.00b 702.00ms -37.00ms 🚀
dist/card.f7371915.js 53.89kb +0.00b 662.00ms -41.00ms 🚀
dist/card.d41d0ab9.js 51.65kb +0.00b 700.00ms -39.00ms 🚀
dist/component.088d2ae3.js 30.87kb +0.00b 595.00ms +68.00ms ⚠️
dist/component.22035ce4.js 22.40kb +0.00b 520.00ms -45.00ms 🚀
dist/js.0a808d22.js 16.55kb +0.00b 520.00ms -26.00ms
dist/dropzone.7ba3ba36.js 15.96kb +0.00b 700.00ms -39.00ms 🚀
dist/component.1880fd07.js 6.27kb +0.00b 524.00ms -91.00ms 🚀
dist/EmojiPickerComponent.55e1f602.js 3.56kb +0.00b 653.00ms -42.00ms 🚀
dist/png-chunks-extract.692b85d1.js 3.55kb +0.00b 595.00ms +49.00ms ⚠️
dist/index.10f02a5e.css 3.46kb +0.00b 705.00ms -39.00ms 🚀
dist/Modal.420db102.js 3.15kb +0.00b 503.00ms -104.00ms 🚀
dist/clipboard.a67b66af.js 2.97kb +0.00b 700.00ms -39.00ms 🚀
dist/16.93e3596b.js 2.49kb +0.00b 502.00ms -42.00ms 🚀
dist/date.c50d5e8c.js 1.96kb +0.00b 584.00ms -40.00ms 🚀
dist/16.8ab9c9cf.js 1.86kb +0.00b 552.00ms -50.00ms 🚀
dist/browser.dfefe24a.js 1.82kb +0.00b 700.00ms -39.00ms 🚀
dist/16.aa2b1e8c.js 1.79kb +0.00b 536.00ms -30.00ms 🚀
dist/list-number.41f28a70.js 1.68kb +0.00b 602.00ms -48.00ms 🚀
dist/status.eb15cda1.js 1.68kb +0.00b 618.00ms -32.00ms 🚀
dist/code.d63c0558.js 1.61kb +0.00b 584.00ms -40.00ms 🚀
dist/link.a9025e77.js 1.53kb +0.00b 595.00ms -55.00ms 🚀
dist/heading3.9115aad6.js 1.51kb +0.00b 615.00ms -42.00ms 🚀
dist/16.b19b33ca.js 1.51kb +0.00b 552.00ms -38.00ms 🚀
dist/16.15d9f682.js 1.46kb +0.00b 536.00ms -30.00ms 🚀
dist/16.fe7e09db.js 1.46kb +0.00b 540.00ms -48.00ms 🚀
dist/16.474c8276.js 1.44kb +0.00b 565.00ms -59.00ms 🚀
dist/16.d49a0bb7.js 1.40kb +0.00b 565.00ms -39.00ms 🚀
dist/heading5.731efbe4.js 1.40kb +0.00b 615.00ms -50.00ms 🚀
dist/16.c4941d0d.js 1.36kb +0.00b 564.00ms -40.00ms 🚀
dist/heading2.de347970.js 1.33kb +0.00b 615.00ms -43.00ms 🚀
dist/16.ad29438e.js 1.32kb +0.00b 565.00ms -39.00ms 🚀
dist/16.3d7a389d.js 1.31kb +0.00b 583.00ms -41.00ms 🚀
dist/mention.1703453a.js 1.29kb +0.00b 603.00ms -47.00ms 🚀
dist/heading4.5089aec7.js 1.29kb +0.00b 615.00ms -50.00ms 🚀
dist/Modal.ae6f5f7a.js 1.28kb +0.00b 520.00ms -26.00ms
dist/layout.32cc11b1.js 1.27kb +0.00b 595.00ms -42.00ms 🚀
dist/16.45835899.js 1.27kb +0.00b 552.00ms -38.00ms 🚀
dist/16.e83a0923.js 1.26kb +0.00b 536.00ms -30.00ms 🚀
dist/16.d315628f.js 1.26kb +0.00b 551.00ms -38.00ms 🚀
dist/16.cc8ae77e.js 1.26kb +0.00b 552.00ms -38.00ms 🚀
dist/16.71387abf.js 1.26kb +0.00b 536.00ms -30.00ms 🚀
dist/quote.b905d023.js 1.25kb +0.00b 618.00ms -32.00ms 🚀
dist/action.3a733320.js 1.23kb +0.00b 583.00ms -41.00ms 🚀
dist/decision.1f5dd6ad.js 1.21kb +0.00b 584.00ms -40.00ms 🚀
dist/16.8cd85281.js 1.18kb +0.00b 565.00ms -39.00ms 🚀
dist/list.7d80b06a.js 1.18kb +0.00b 602.00ms -48.00ms 🚀
dist/heading1.c1474f93.js 1.18kb +0.00b 614.00ms -36.00ms 🚀
dist/media-picker-analytics-error-boundary.607a1e52.js 1.05kb +0.00b 695.00ms -44.00ms 🚀
dist/media-card-analytics-error-boundary.f92fc998.js 1.05kb +0.00b 662.00ms -49.00ms 🚀
dist/simpleHasher.26a74474.js 755.00b +0.00b 646.00ms -49.00ms 🚀
dist/index.html 119.00b +0.00b 504.00ms -40.00ms 🚀

Three.js ✅

Timings

Description Time Difference
Cold 15.59s -384.00ms
Cached 708.00ms +39.00ms ⚠️

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Click here to view a detailed benchmark overview.

@mischnic mischnic force-pushed the css-modules-tree-shaking branch 3 times, most recently from 8fea0fd to cae5b33 Compare December 12, 2020 11:45
@@ -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",
Copy link
Member Author

@mischnic mischnic Dec 15, 2020

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

@mischnic mischnic marked this pull request as ready for review December 15, 2020 16:16
[...asset.symbols].map(([, {local}]) => `.${local}`),
);
let usedLocalSymbols =
// we have to still support the more common default imports
Copy link
Member

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?

Copy link
Member Author

@mischnic mischnic Dec 23, 2020

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....

Copy link
Member

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...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bildschirmfoto 2020-12-30 um 13 09 47

Copy link
Member

@devongovett devongovett left a 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)
Copy link
Member

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',
Copy link
Member

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 😉

@devongovett devongovett merged commit 94e531f into v2 Jan 2, 2021
@devongovett devongovett deleted the css-modules-tree-shaking branch January 2, 2021 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants