Skip to content

Commit 381d470

Browse files
committed
feat: do not hash localName if the localName is inlined: rename option values
1 parent 4c07771 commit 381d470

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -874,13 +874,13 @@ module.exports = {
874874

875875
##### `hashStrategy`
876876

877-
Type: `'use-local-name' | 'auto'`
878-
Default: `'use-local-name'`
877+
Type: `'resource-path-and-local-name' | 'minimal-subset'`
878+
Default: `'resource-path-and-local-name'`
879879

880880
Should local name be used when computing the hash.
881881

882-
- `'use-local-name'` Each identifier in a module gets its own hash digest.
883-
- `'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.
882+
- `'resource-path-and-local-name'` Both resource path and local name are used when hashing. Each identifier in a module gets its own hash digest, always.
883+
- `'minimal-subset'` Auto detect if identifier names can be omitted from hashing. Use this value to optimize the output for better GZIP or Brotli compression.
884884

885885
**webpack.config.js**
886886

@@ -893,7 +893,7 @@ module.exports = {
893893
loader: "css-loader",
894894
options: {
895895
modules: {
896-
hashStrategy: "auto",
896+
hashStrategy: "minimal-subset",
897897
},
898898
},
899899
},

src/options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"hashStrategy": {
118118
"description": "Allows to specify should localName be used when computing the hash.",
119119
"link": "https://github.com/webpack-contrib/css-loader#hashstrategy",
120-
"enum": ["use-local-name", "auto"]
120+
"enum": ["resource-path-and-local-name", "minimal-subset"]
121121
},
122122
"localIdentRegExp": {
123123
"description": "Allows to specify custom RegExp for local ident name.",

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ function defaultGetLocalIdent(
338338

339339
// eslint-disable-next-line no-param-reassign
340340
options.content =
341-
hashStrategy === "auto" && /\[local\]/.test(localIdentName)
341+
hashStrategy === "minimal-subset" && /\[local\]/.test(localIdentName)
342342
? relativeResourcePath
343343
: `${relativeResourcePath}\x00${localName}`;
344344

test/__snapshots__/modules-option.test.js.snap

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,9 +3397,9 @@ Array [
33973397

33983398
exports[`"modules" option should work and respect the "hashSalt" option: warnings 1`] = `Array []`;
33993399

3400-
exports[`"modules" option should work and respect the "hashStrategy" = "auto" and [local]: errors 1`] = `Array []`;
3400+
exports[`"modules" option should work and respect the "hashStrategy" = "minimal-subset" and [local]: errors 1`] = `Array []`;
34013401

3402-
exports[`"modules" option should work and respect the "hashStrategy" = "auto" and [local]: module 1`] = `
3402+
exports[`"modules" option should work and respect the "hashStrategy" = "minimal-subset" and [local]: module 1`] = `
34033403
"// Imports
34043404
import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \\"../../../../src/runtime/noSourceMaps.js\\";
34053405
import ___CSS_LOADER_API_IMPORT___ from \\"../../../../src/runtime/api.js\\";
@@ -3461,7 +3461,7 @@ export default ___CSS_LOADER_EXPORT___;
34613461
"
34623462
`;
34633463

3464-
exports[`"modules" option should work and respect the "hashStrategy" = "auto" and [local]: result 1`] = `
3464+
exports[`"modules" option should work and respect the "hashStrategy" = "minimal-subset" and [local]: result 1`] = `
34653465
Array [
34663466
Array [
34673467
"./modules/localIdentName/localIdentName.css",
@@ -3585,11 +3585,11 @@ Array [
35853585
]
35863586
`;
35873587

3588-
exports[`"modules" option should work and respect the "hashStrategy" = "auto" and [local]: warnings 1`] = `Array []`;
3588+
exports[`"modules" option should work and respect the "hashStrategy" = "minimal-subset" and [local]: warnings 1`] = `Array []`;
35893589

3590-
exports[`"modules" option should work and respect the "hashStrategy" = "auto" and no [local]: errors 1`] = `Array []`;
3590+
exports[`"modules" option should work and respect the "hashStrategy" = "minimal-subset" and no [local]: errors 1`] = `Array []`;
35913591

3592-
exports[`"modules" option should work and respect the "hashStrategy" = "auto" and no [local]: module 1`] = `
3592+
exports[`"modules" option should work and respect the "hashStrategy" = "minimal-subset" and no [local]: module 1`] = `
35933593
"// Imports
35943594
import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \\"../../../../src/runtime/noSourceMaps.js\\";
35953595
import ___CSS_LOADER_API_IMPORT___ from \\"../../../../src/runtime/api.js\\";
@@ -3651,7 +3651,7 @@ export default ___CSS_LOADER_EXPORT___;
36513651
"
36523652
`;
36533653

3654-
exports[`"modules" option should work and respect the "hashStrategy" = "auto" and no [local]: result 1`] = `
3654+
exports[`"modules" option should work and respect the "hashStrategy" = "minimal-subset" and no [local]: result 1`] = `
36553655
Array [
36563656
Array [
36573657
"./modules/localIdentName/localIdentName.css",
@@ -3775,11 +3775,11 @@ Array [
37753775
]
37763776
`;
37773777

3778-
exports[`"modules" option should work and respect the "hashStrategy" = "auto" and no [local]: warnings 1`] = `Array []`;
3778+
exports[`"modules" option should work and respect the "hashStrategy" = "minimal-subset" and no [local]: warnings 1`] = `Array []`;
37793779

3780-
exports[`"modules" option should work and respect the "hashStrategy" = "use-local-name": errors 1`] = `Array []`;
3780+
exports[`"modules" option should work and respect the "hashStrategy" = "resource-path-and-local-name": errors 1`] = `Array []`;
37813781

3782-
exports[`"modules" option should work and respect the "hashStrategy" = "use-local-name": module 1`] = `
3782+
exports[`"modules" option should work and respect the "hashStrategy" = "resource-path-and-local-name": module 1`] = `
37833783
"// Imports
37843784
import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \\"../../../../src/runtime/noSourceMaps.js\\";
37853785
import ___CSS_LOADER_API_IMPORT___ from \\"../../../../src/runtime/api.js\\";
@@ -3841,7 +3841,7 @@ export default ___CSS_LOADER_EXPORT___;
38413841
"
38423842
`;
38433843

3844-
exports[`"modules" option should work and respect the "hashStrategy" = "use-local-name": result 1`] = `
3844+
exports[`"modules" option should work and respect the "hashStrategy" = "resource-path-and-local-name": result 1`] = `
38453845
Array [
38463846
Array [
38473847
"./modules/localIdentName/localIdentName.css",
@@ -3965,7 +3965,7 @@ Array [
39653965
]
39663966
`;
39673967

3968-
exports[`"modules" option should work and respect the "hashStrategy" = "use-local-name": warnings 1`] = `Array []`;
3968+
exports[`"modules" option should work and respect the "hashStrategy" = "resource-path-and-local-name": warnings 1`] = `Array []`;
39693969

39703970
exports[`"modules" option should work and respect the "localConvention" option with the "asIs" value: errors 1`] = `Array []`;
39713971

test/modules-option.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,12 @@ describe('"modules" option', () => {
381381
expect(getErrors(stats)).toMatchSnapshot("errors");
382382
});
383383

384-
it('should work and respect the "hashStrategy" = "use-local-name"', async () => {
384+
it('should work and respect the "hashStrategy" = "resource-path-and-local-name"', async () => {
385385
const compiler = getCompiler("./modules/localIdentName/localIdentName.js", {
386386
modules: {
387387
localIdentName: "[local]__[hash:base64:8]",
388388
// localName should be used even if [local] is contained in the localIdentName template
389-
hashStrategy: "use-local-name",
389+
hashStrategy: "resource-path-and-local-name",
390390
},
391391
});
392392
const stats = await compile(compiler);
@@ -401,12 +401,12 @@ describe('"modules" option', () => {
401401
expect(getErrors(stats)).toMatchSnapshot("errors");
402402
});
403403

404-
it('should work and respect the "hashStrategy" = "auto" and [local]', async () => {
404+
it('should work and respect the "hashStrategy" = "minimal-subset" and [local]', async () => {
405405
const compiler = getCompiler("./modules/localIdentName/localIdentName.js", {
406406
modules: {
407407
localIdentName: "[local]__[hash:base64:8]",
408408
// localName should not be used: [local] is used
409-
hashStrategy: "auto",
409+
hashStrategy: "minimal-subset",
410410
},
411411
});
412412
const stats = await compile(compiler);
@@ -421,12 +421,12 @@ describe('"modules" option', () => {
421421
expect(getErrors(stats)).toMatchSnapshot("errors");
422422
});
423423

424-
it('should work and respect the "hashStrategy" = "auto" and no [local]', async () => {
424+
it('should work and respect the "hashStrategy" = "minimal-subset" and no [local]', async () => {
425425
const compiler = getCompiler("./modules/localIdentName/localIdentName.js", {
426426
modules: {
427427
localIdentName: "[hash:base64:8]",
428428
// localName should be used: [local] is not used
429-
hashStrategy: "auto",
429+
hashStrategy: "minimal-subset",
430430
},
431431
});
432432
const stats = await compile(compiler);

0 commit comments

Comments
 (0)