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
feat: do not hash localName if the localName is inlined #1410
feat: do not hash localName if the localName is inlined #1410
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1410 +/- ##
=======================================
Coverage 96.80% 96.81%
=======================================
Files 12 12
Lines 1127 1130 +3
Branches 408 411 +3
=======================================
+ Hits 1091 1094 +3
Misses 27 27
Partials 9 9
Continue to review full report at Codecov.
|
Let's move this under option to avoid breaking changes, we can set it by default in the next major release |
Sounds reasonable! How should I better do and name it? Adding a new setting Or should it be something more generic like UPD: I'm going with the |
I think |
f7f3072
to
88130b6
Compare
Adds a new setting .modules.hashStrategy, default is backward-compat
88130b6
to
8e93b75
Compare
___CSS_LOADER_EXPORT___.push([module.id, \\".iHMJbI42 {\\\\n background: red;\\\\n}\\\\n\\\\n.iHMJbI42 {\\\\n background: blue;\\\\n}\\\\n\\\\n.iHMJbI42 {\\\\n background: red;\\\\n}\\\\n\\\\n#iHMJbI42 {\\\\n background: green;\\\\n}\\\\n\\\\n.iHMJbI42 .iHMJbI42 {\\\\n color: green;\\\\n}\\\\n\\\\n#iHMJbI42 .iHMJbI42 {\\\\n color: blue;\\\\n}\\\\n\\\\n.iHMJbI42 {\\\\n color: red;\\\\n}\\\\n\\\\n.iHMJbI42 {\\\\n margin-left: auto !important;\\\\n margin-right: auto !important;\\\\n}\\\\n\\\\n.iHMJbI42 {\\\\n margin-left: auto !important;\\\\n margin-right: auto !important;\\\\n}\\\\n\\\\n/* matches elements with class=\\\\\\":\`(\\\\\\" */\\\\n.iHMJbI42 {\\\\n color: aqua;\\\\n}\\\\n\\\\n/* matches elements with class=\\\\\\"1a2b3c\\\\\\" */\\\\n.iHMJbI42 {\\\\n color: aliceblue;\\\\n}\\\\n\\\\n/* matches the element with id=\\\\\\"#fake-id\\\\\\" */\\\\n#iHMJbI42 {\\\\n color: antiquewhite;\\\\n}\\\\n\\\\n/* matches the element with id=\\\\\\"-a-b-c-\\\\\\" */\\\\n#iHMJbI42 {\\\\n color: azure;\\\\n}\\\\n\\\\n/* matches the element with id=\\\\\\"©\\\\\\" */\\\\n#iHMJbI42 {\\\\n color: black;\\\\n}\\\\n\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n.iHMJbI42 { background: lime; }\\\\n\\\\n.iHMJbI42 {\\\\n background: hotpink;\\\\n}\\\\n\\\\n.iHMJbI42 {\\\\n background: hotpink;\\\\n}\\\\n\\\\n.iHMJbI42 {\\\\n background: hotpink;\\\\n}\\\\n\\\\n.iHMJbI42 {\\\\n background: hotpink;\\\\n}\\\\n\\", \\"\\"]); | ||
// Exports | ||
___CSS_LOADER_EXPORT___.locals = { | ||
\\"123\\": \\"iHMJbI42\\", |
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.
On a second thought, it's hard to imagine a use-case when 'omit-local-name'
could be used:
- If
[local]
is used, it works just like'auto'
. - If
[local]
is not there, it screws everything up.
Should we keep it for completeness and probably #1181 like features?
Or is it a bad idea too keep senseless options and it should better be removed?
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's avoid senseless options, we can add them late, if we will need
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.
Done, in 976ff89
Remove senseless .modules.hashStrategy = "omit-local-name"
@subzey Looks good, let's regenerate lock file due security problem in CI 👍 |
EPERM on Windows? I hope we could just restart the test and have it fixed |
I fixed the problem |
README.md
Outdated
Should local name be used when computing the hash. | ||
|
||
- `'use-local-name'` Each identifier in a module gets its own hash digest. | ||
- `'auto'` Identifiers from the same module shares the same hash digest if it's possible. Use this value to optimize the output for better GZIP or Brotli compression. |
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.
After review, I think 'auto'
is not good name, 'auto'
sounds like it should be default value, yes, maybe this should be the default (as I written above), but let's found better name, I think we can do it more understandable, I suggest: resource-path
and resource-path-and-local-name
, the developer can immediately understand what is used from the name, instead of reading the documentation
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.
There's a chance a developer would set a resource-path
, but the hashing would work as resource-path-and-local-name
because of the automagic circuit breaker. That may lead to confusion, especially when copypasting the config partially into StackOverflow or GH issues.
Maybe minimal-subset
or infer-from-template
or something like that? Something that implies the automatic nature of the setting
I'm not a big fan of bikeshedding and just will use your suggestion if we don't come up with a decision after a short while
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's use minimal-subset
👍
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.
Renamed the option enum values in 381d470
a4c8f2b
to
381d470
Compare
Thanks |
This is really nice.
Upgrading css-loader to version 6.7.1 worked for me :) |
This PR contains a:
Motivation / Use-Case
Proposal: The
localName
should not affect the hash if it is present in the generated id inline. This way the generated identifiers are compressed better with both GZIP and Brotli.Currently the hash is computed from the file relative path and the local identifier name. It's good when the
[local]
is not preset in the templatelocalIdentName
:But it is redundant if the
[local]
is present:The
.button
fromone.css
and.button
fromtwo.css
still have to have different hashes.But the
.header
fromone.css
and.button
from the sameone.css
can never collide, they're from the same module! Omitting localName from the hash we get:Now all identifiers from the same module has the same hash. (If and only if the
localName
would be substituted into the resulting generated identifier!) And there are less unique random string runs in the output, making the result more GZIP friendly.I've used
test/__snapshots__/modules-option.test.js.snap
for my "gzippability" estimations. This file "before" and "after" has the same "raw" byte length. But the "after" is almost 8% smaller after being GZIPpedWe use the similar technique on tradingview.com for a year or so -- using custom
getLocalIdent()
in the webpack settings. But now it's time to reveal one of our optimization secrets 😀Breaking Changes
None
Additional Info
⚠️ The generated identifiers will change compared to the previous versions - only if the -- Postponed to the next major release.[local]
is used in the template.