Skip to content

Commit c44418f

Browse files
refactor: code
1 parent 62ef216 commit c44418f

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

src/utils.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,22 @@ function defaultGetLocalIdent(
6868
localName,
6969
options
7070
) {
71-
let matchResourceRequest;
72-
73-
// // eslint-disable-next-line no-underscore-dangle
74-
// if (loaderContext._module.matchResource) {
75-
// matchResourceRequest = normalizePath(
76-
// // eslint-disable-next-line no-underscore-dangle
77-
// path.relative(options.context, loaderContext._module.matchResource)
78-
// );
79-
// }
71+
let relativeMatchResource = "";
72+
73+
// eslint-disable-next-line no-underscore-dangle
74+
if (loaderContext._module.matchResource) {
75+
relativeMatchResource = `${normalizePath(
76+
// eslint-disable-next-line no-underscore-dangle
77+
path.relative(options.context, loaderContext._module.matchResource)
78+
)}\x00`;
79+
}
8080

81-
const request = normalizePath(
81+
const relativeResourcePath = normalizePath(
8282
path.relative(options.context, loaderContext.resourcePath)
8383
);
8484

8585
// eslint-disable-next-line no-param-reassign
86-
options.content = `${
87-
options.hashPrefix +
88-
(typeof matchResourceRequest !== "undefined"
89-
? `${matchResourceRequest}\x00`
90-
: "") +
91-
request
92-
}\x00${localName}`;
86+
options.content = `${options.hashPrefix}${relativeMatchResource}${relativeResourcePath}\x00${localName}`;
9387

9488
return interpolateName(loaderContext, localIdentName, options);
9589
}

test/__snapshots__/loader.test.js.snap

Lines changed: 15 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+
"._14oM7qkZ6dgC62uK5h4NI0 {
669669
color: red;
670670
}
671671
672-
.j3CQSVq_DdDvo0Ew74yQi {
672+
._2NqyYysncZeLetATpl0xfW {
673673
color: white;
674674
}",
675675
"",
676676
],
677677
Array [
678678
"button.modules.css!=!./index-loader-syntax-sass.css",
679-
".iuzmhXWrT3_Z-zKS-rMGM {
679+
"._8aapa4kQQdSsOoRODcrwe {
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+
"._2yVYVQfmDwKLZn9Qj6k_Q5 > ._3rHlnRnPEotX4nTkd82-aE {
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+
"._14oM7qkZ6dgC62uK5h4NI0 {
694694
color: red;
695695
}
696696
697-
.j3CQSVq_DdDvo0Ew74yQi {
697+
._2NqyYysncZeLetATpl0xfW {
698698
color: white;
699699
}
700700
701-
.B7fdaUjwJ3YVou1v7dYEE {
701+
._1-Aa1c8UQML46IWY0FjGXT {
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+
"._14oM7qkZ6dgC62uK5h4NI0 {
709709
color: red;
710710
}
711711
712-
.j3CQSVq_DdDvo0Ew74yQi {
712+
._2NqyYysncZeLetATpl0xfW {
713713
color: white;
714714
}
715715
716-
.B7fdaUjwJ3YVou1v7dYEE {
716+
._1-Aa1c8UQML46IWY0FjGXT {
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+
"._2yVYVQfmDwKLZn9Qj6k_Q5 > ._3rHlnRnPEotX4nTkd82-aE {
724724
color: red;
725725
}
726726
727-
._1kK_VYa-N303wnLgpvL-7d {
727+
._2kEhhupr-6tgHnCC_d4yO8 {
728728
from: custom;
729729
}",
730730
"",
@@ -738,21 +738,21 @@ Array [
738738
],
739739
Array [
740740
"button.modules.css!=!./index-loader-syntax-sass.css",
741-
".iuzmhXWrT3_Z-zKS-rMGM {
741+
"._8aapa4kQQdSsOoRODcrwe {
742742
width: 5px;
743743
}",
744744
"",
745745
],
746746
Array [
747747
"button.module.scss!=!./base64-loader/index.js?[ident]!./simple.js?foo=bar",
748-
"._1DaPRMj4jImbX3XSIzjaR4 {
748+
"._2hfVrRfux-FOrqimHr-fzt {
749749
color: red;
750750
}",
751751
"",
752752
],
753753
Array [
754754
"other.module.scss!=!./base64-loader/index.js?[ident]!./simple.js?foo=baz",
755-
"._1DaPRMj4jImbX3XSIzjaR4 {
755+
"._2jOyhMQwdpQ85V5dDLcfoG {
756756
color: red;
757757
}",
758758
"",

0 commit comments

Comments
 (0)