Skip to content

Commit 2f4c273

Browse files
fix: css modules generation with inline syntax (#1480)
1 parent 7c5cdcc commit 2f4c273

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

src/utils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,18 @@ function defaultGetLocalIdent(
332332
) {
333333
const { context, hashSalt, hashStrategy } = options;
334334
const { resourcePath } = loaderContext;
335-
const relativeResourcePath = normalizePath(
335+
let relativeResourcePath = normalizePath(
336336
path.relative(context, resourcePath)
337337
);
338338

339+
// eslint-disable-next-line no-underscore-dangle
340+
if (loaderContext._module && loaderContext._module.matchResource) {
341+
relativeResourcePath = `${normalizePath(
342+
// eslint-disable-next-line no-underscore-dangle
343+
path.relative(context, loaderContext._module.matchResource)
344+
)}`;
345+
}
346+
339347
// eslint-disable-next-line no-param-reassign
340348
options.content =
341349
hashStrategy === "minimal-subset" && /\[local\]/.test(localIdentName)

test/__snapshots__/loader.test.js.snap

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -852,66 +852,66 @@ exports[`loader should work with inline module syntax: result 1`] = `
852852
Array [
853853
Array [
854854
"other.modules.css!=!../../src/index.js??ruleSet[1].rules[0].rules[0]!../../node_modules/sass-loader/dist/cjs.js!./index-loader-syntax.modules.css",
855-
".L34UCpsDMDUf5cci5FTp {
855+
".ZVx7VAdLOO3PJ1TqkYUn {
856856
color: red;
857857
}
858858
859-
.cR0dzE36E911coHAsfAF {
859+
.x0BV6RnIqi6PTJ6If2oA {
860860
color: white;
861861
}",
862862
"",
863863
],
864864
Array [
865865
"button.modules.css!=!./index-loader-syntax-sass.css",
866-
".Bm6FV6LbXUxAkIaBjl7y {
866+
".n6iVkcAs9Wu9ovztqf8g {
867867
width: 5px;
868868
}",
869869
"",
870870
],
871871
Array [
872872
"other.modules.scss!=!../../src/index.js??ruleSet[1].rules[0].rules[0]!../../node_modules/sass-loader/dist/cjs.js!./index-loader-syntax-sass.modules.css",
873-
".JkECLtXaeLgZptjLMVOV > .cg9Qb_Gz48g_sQh4Pjap {
873+
".NF9v028MAhreSp2TJZnn > .ss2pNzM7P7DcLJerCZFm {
874874
color: red;
875875
}",
876876
"",
877877
],
878878
Array [
879879
"other.modules.css!=!../../src/index.js??ruleSet[1].rules[0].rules[0]!../../node_modules/sass-loader/dist/cjs.js!./my-inline-loader/index.js!./index-loader-syntax.modules.css",
880-
".L34UCpsDMDUf5cci5FTp {
880+
".ZVx7VAdLOO3PJ1TqkYUn {
881881
color: red;
882882
}
883883
884-
.cR0dzE36E911coHAsfAF {
884+
.x0BV6RnIqi6PTJ6If2oA {
885885
color: white;
886886
}
887887
888-
.BBGEY4nuDapXZ5Z5Llcd {
888+
.bNEIH_2ycglHGlceq20s {
889889
from: custom;
890890
}",
891891
"",
892892
],
893893
Array [
894894
"other.modules.css!=!../../src/index.js??ruleSet[1].rules[0].rules[0]!../../node_modules/sass-loader/dist/cjs.js!./my-inline-loader/index.js!./index-loader-syntax.modules.css",
895-
".L34UCpsDMDUf5cci5FTp {
895+
".ZVx7VAdLOO3PJ1TqkYUn {
896896
color: red;
897897
}
898898
899-
.cR0dzE36E911coHAsfAF {
899+
.x0BV6RnIqi6PTJ6If2oA {
900900
color: white;
901901
}
902902
903-
.BBGEY4nuDapXZ5Z5Llcd {
903+
.bNEIH_2ycglHGlceq20s {
904904
from: custom;
905905
}",
906906
"",
907907
],
908908
Array [
909909
"other.modules.scss!=!../../src/index.js??ruleSet[1].rules[0].rules[0]!../../node_modules/sass-loader/dist/cjs.js!./my-inline-loader/index.js!./index-loader-syntax-sass.modules.css",
910-
".JkECLtXaeLgZptjLMVOV > .cg9Qb_Gz48g_sQh4Pjap {
910+
".NF9v028MAhreSp2TJZnn > .ss2pNzM7P7DcLJerCZFm {
911911
color: red;
912912
}
913913
914-
.WJ9UGZwK6YvLQsxARKO1 {
914+
.NMxzPXmuJS2nd8LarB5I {
915915
from: custom;
916916
}",
917917
"",
@@ -925,21 +925,21 @@ Array [
925925
],
926926
Array [
927927
"button.modules.css!=!./index-loader-syntax-sass.css",
928-
".Bm6FV6LbXUxAkIaBjl7y {
928+
".n6iVkcAs9Wu9ovztqf8g {
929929
width: 5px;
930930
}",
931931
"",
932932
],
933933
Array [
934934
"button.module.scss!=!./base64-loader/index.js?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./simple.js?foo=bar",
935-
".nQ7qpE_fxjuYDsViKqtM {
935+
".QwIaKzIX2nnuKwGnu953 {
936936
color: red;
937937
}",
938938
"",
939939
],
940940
Array [
941941
"other.module.scss!=!./base64-loader/index.js?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./simple.js?foo=baz",
942-
".nQ7qpE_fxjuYDsViKqtM {
942+
".L_0U1ZWuSHuIqdUV6KjO {
943943
color: red;
944944
}",
945945
"",

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5851,11 +5851,11 @@ import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \\"../../src/runtime/noSour
58515851
import ___CSS_LOADER_API_IMPORT___ from \\"../../src/runtime/api.js\\";
58525852
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___);
58535853
// Module
5854-
___CSS_LOADER_EXPORT___.push([module.id, \\".dvYI1gdIOPlJqjwAWOo8 {\\\\n color: red;\\\\n}\\\\n\\\\n.s4qiGaiPSoYikcMyZg9a { from: custom; }\\", \\"\\"]);
5854+
___CSS_LOADER_EXPORT___.push([module.id, \\".mCRIw6YAFAAC3_rE9RUZ {\\\\n color: red;\\\\n}\\\\n\\\\n.bNEIH_2ycglHGlceq20s { from: custom; }\\", \\"\\"]);
58555855
// Exports
58565856
___CSS_LOADER_EXPORT___.locals = {
5857-
\\"some-class\\": \\"dvYI1gdIOPlJqjwAWOo8\\",
5858-
\\"class\\": \\"s4qiGaiPSoYikcMyZg9a\\"
5857+
\\"some-class\\": \\"mCRIw6YAFAAC3_rE9RUZ\\",
5858+
\\"class\\": \\"bNEIH_2ycglHGlceq20s\\"
58595859
};
58605860
export default ___CSS_LOADER_EXPORT___;
58615861
"
@@ -5890,11 +5890,11 @@ Array [
58905890
],
58915891
Array [
58925892
"other.modules.css!=!./my-inline-loader/index.js!./simple.css",
5893-
".dvYI1gdIOPlJqjwAWOo8 {
5893+
".mCRIw6YAFAAC3_rE9RUZ {
58945894
color: red;
58955895
}
58965896

5897-
.s4qiGaiPSoYikcMyZg9a { from: custom; }",
5897+
.bNEIH_2ycglHGlceq20s { from: custom; }",
58985898
"",
58995899
],
59005900
Array [

test/fixtures/index-loader-syntax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ import four from './other.module.scss!=!./base64-loader?LmZvbyB7IGNvbG9yOiByZWQ7
66

77
__export__ = [...one, ...two, ...three, ...four];
88

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy