Skip to content

Commit 583a9d1

Browse files
fix: ident generation
1 parent 7f5d98c commit 583a9d1

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

src/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,17 @@ function defaultGetLocalIdent(
6969
options
7070
) {
7171
const { context, hashPrefix } = options;
72+
// eslint-disable-next-line no-underscore-dangle
73+
const { matchResource } = loaderContext._module;
7274
const { resourcePath } = loaderContext;
7375
const request = normalizePath(path.relative(context, resourcePath));
7476

7577
// eslint-disable-next-line no-param-reassign
76-
options.content = `${hashPrefix + request}\x00${localName}`;
78+
options.content = `${
79+
hashPrefix +
80+
(typeof matchResource !== "undefined" ? `${matchResource}\x00` : "") +
81+
request
82+
}\x00${localName}`;
7783

7884
return interpolateName(loaderContext, localIdentName, options);
7985
}

test/__snapshots__/loader.test.js.snap

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -665,66 +665,66 @@ exports[`loader should work with inline module syntax: result 1`] = `
665665
Array [
666666
Array [
667667
"other.modules.css!=!../../src/index.js?[ident]!./index-loader-syntax.modules.css",
668-
"._1ZJhuRHDA53bY_Z4Qfm2b4 {
668+
"._3FhluglYfH54WWRd2Lmpsy {
669669
color: red;
670670
}
671671
672-
.j3CQSVq_DdDvo0Ew74yQi {
672+
._3danpknEEa0R3CZCkFeRI0 {
673673
color: white;
674674
}",
675675
"",
676676
],
677677
Array [
678678
"button.modules.css!=!./index-loader-syntax-sass.css",
679-
".iuzmhXWrT3_Z-zKS-rMGM {
679+
".C6WgXrKWbFsSifATWfzu {
680680
width: 5px;
681681
}",
682682
"",
683683
],
684684
Array [
685685
"other.modules.scss!=!../../src/index.js?[ident]!./index-loader-syntax-sass.modules.css",
686-
"._1fGl5mRxLFCqIet0X3JYrB > ._2pVMnENaxk1YmKug-4EMYF {
686+
"._2r_y8mGYyCwfbs1_VPTK5C > ._1yssyumFL0m4gBbuzRhER2 {
687687
color: red;
688688
}",
689689
"",
690690
],
691691
Array [
692692
"other.modules.css!=!../../src/index.js?[ident]!./index-loader-syntax.modules.css",
693-
"._1ZJhuRHDA53bY_Z4Qfm2b4 {
693+
"._3FhluglYfH54WWRd2Lmpsy {
694694
color: red;
695695
}
696696
697-
.j3CQSVq_DdDvo0Ew74yQi {
697+
._3danpknEEa0R3CZCkFeRI0 {
698698
color: white;
699699
}
700700
701-
.B7fdaUjwJ3YVou1v7dYEE {
701+
._3lQ9E7_p8EySCyfUghDtwz {
702702
from: custom;
703703
}",
704704
"",
705705
],
706706
Array [
707707
"other.modules.css!=!../../src/index.js?[ident]!./index-loader-syntax.modules.css",
708-
"._1ZJhuRHDA53bY_Z4Qfm2b4 {
708+
"._3FhluglYfH54WWRd2Lmpsy {
709709
color: red;
710710
}
711711
712-
.j3CQSVq_DdDvo0Ew74yQi {
712+
._3danpknEEa0R3CZCkFeRI0 {
713713
color: white;
714714
}
715715
716-
.B7fdaUjwJ3YVou1v7dYEE {
716+
._3lQ9E7_p8EySCyfUghDtwz {
717717
from: custom;
718718
}",
719719
"",
720720
],
721721
Array [
722722
"other.modules.scss!=!../../src/index.js?[ident]!./index-loader-syntax-sass.modules.css",
723-
"._1fGl5mRxLFCqIet0X3JYrB > ._2pVMnENaxk1YmKug-4EMYF {
723+
"._2r_y8mGYyCwfbs1_VPTK5C > ._1yssyumFL0m4gBbuzRhER2 {
724724
color: red;
725725
}
726726
727-
._1kK_VYa-N303wnLgpvL-7d {
727+
._3B3N-_-uymcqQkGiRwYhjx {
728728
from: custom;
729729
}",
730730
"",
@@ -738,14 +738,21 @@ Array [
738738
],
739739
Array [
740740
"button.modules.css!=!./index-loader-syntax-sass.css",
741-
".iuzmhXWrT3_Z-zKS-rMGM {
741+
".C6WgXrKWbFsSifATWfzu {
742742
width: 5px;
743743
}",
744744
"",
745745
],
746746
Array [
747-
"button.module.scss!=!./base64-loader/index.js?[ident]!./simple.js",
748-
"._1DaPRMj4jImbX3XSIzjaR4 {
747+
"button.module.scss!=!./base64-loader/index.js?[ident]!./simple.js?foo=bar",
748+
"._1Z1CpM4SYZX9egsUO4gNTz {
749+
color: red;
750+
}",
751+
"",
752+
],
753+
Array [
754+
"other.module.scss!=!./base64-loader/index.js?[ident]!./simple.js?foo=baz",
755+
"._1KqQu-H04lA8NLg4-NKnDf {
749756
color: red;
750757
}",
751758
"",

test/fixtures/index-loader-syntax.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import one from './index-loader-syntax.css';
22
import two from 'button.modules.css!=!./index-loader-syntax-sass.css';
3-
import three from './button.module.scss!=!./base64-loader?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./simple.js';
3+
// Hash should be different
4+
import three from './button.module.scss!=!./base64-loader?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./simple.js?foo=bar';
5+
import four from './other.module.scss!=!./base64-loader?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./simple.js?foo=baz';
46

5-
__export__ = [...one, ...two, ...three];
7+
__export__ = [...one, ...two, ...three, ...four];
68

7-
export default [...one, ...two, ...three];
9+
export default [...one, ...two, ...three, ...four];

test/sourceMap-option.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ describe('"sourceMap" option', () => {
501501

502502
expect(chunkName).toBe(
503503
webpack.version[0] === "5"
504-
? "main.a531550ffe767c49e881.bundle.js"
504+
? "main.89840c70616b788038a2.bundle.js"
505505
: "main.19efc497c5c37fc5e355.bundle.js"
506506
);
507507
expect(

0 commit comments

Comments
 (0)