Skip to content

Commit b68420a

Browse files
fix: resolve modules
1 parent edf5347 commit b68420a

File tree

7 files changed

+181
-0
lines changed

7 files changed

+181
-0
lines changed

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

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,104 @@ Array [
10421042
10431043
exports[`"modules" option should should work with two leading underscore: warnings 1`] = `Array []`;
10441044
1045+
exports[`"modules" option should support resolving in composes preprocessor files with extensions: errors 1`] = `Array []`;
1046+
1047+
exports[`"modules" option should support resolving in composes preprocessor files with extensions: module 1`] = `
1048+
"// Imports
1049+
var ___CSS_LOADER_API_IMPORT___ = require(\\"../../../../src/runtime/api.js\\");
1050+
var ___CSS_LOADER_ICSS_IMPORT_0___ = require(\\"-!../../../../src/index.js??[ident]!./values.css\\");
1051+
var ___CSS_LOADER_ICSS_IMPORT_1___ = require(\\"-!../../../../src/index.js??[ident]!./less-file.less\\");
1052+
var ___CSS_LOADER_ICSS_IMPORT_2___ = require(\\"-!../../../../src/index.js??[ident]!./scss-file.scss\\");
1053+
var ___CSS_LOADER_ICSS_IMPORT_3___ = require(\\"-!../../../../src/index.js??[ident]!./sass-file.sass\\");
1054+
exports = ___CSS_LOADER_API_IMPORT___(false);
1055+
exports.i(___CSS_LOADER_ICSS_IMPORT_0___, \\"\\", true);
1056+
exports.i(___CSS_LOADER_ICSS_IMPORT_1___, \\"\\", true);
1057+
exports.i(___CSS_LOADER_ICSS_IMPORT_2___, \\"\\", true);
1058+
exports.i(___CSS_LOADER_ICSS_IMPORT_3___, \\"\\", true);
1059+
// Module
1060+
exports.push([module.id, \\".globalClassName {\\\\n color: orange;\\\\n}\\\\n\\\\n._2vZioV5tEV-AlqaI8c_mtN {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"v-def\\"] + \\";\\\\n}\\\\n\\\\n.YX1POP6L7ESwR7pdtyRna {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"v-foo\\"] + \\";\\\\n}\\\\n\\\\n._1578mz8iEiOG2qNa19R11c {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_2___.locals[\\"v-bar\\"] + \\";\\\\n}\\\\n\\\\n._1yWiOyfH6HuDl7TOzpnWkK {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_3___.locals[\\"v-baz\\"] + \\";\\\\n}\\\\n\\\\n.OVj95yO5B9JEdIo3xDMtO {\\\\n background: #000;\\\\n}\\\\n\\", \\"\\"]);
1061+
// Exports
1062+
exports.locals = {
1063+
\\"v-def\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"v-def\\"] + \\"\\",
1064+
\\"v-foo\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"v-foo\\"] + \\"\\",
1065+
\\"v-bar\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_2___.locals[\\"v-bar\\"] + \\"\\",
1066+
\\"v-baz\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_3___.locals[\\"v-baz\\"] + \\"\\",
1067+
\\"globalClassName\\": \\"globalClassName\\",
1068+
\\"ghi\\": \\"_2vZioV5tEV-AlqaI8c_mtN\\",
1069+
\\"class\\": \\"YX1POP6L7ESwR7pdtyRna \\" + ___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"lessClass\\"] + \\"\\",
1070+
\\"other\\": \\"_1578mz8iEiOG2qNa19R11c \\" + ___CSS_LOADER_ICSS_IMPORT_2___.locals[\\"scssClass\\"] + \\"\\",
1071+
\\"last\\": \\"_1yWiOyfH6HuDl7TOzpnWkK \\" + ___CSS_LOADER_ICSS_IMPORT_3___.locals[\\"sassClass\\"] + \\"\\",
1072+
\\"otherClassName\\": \\"OVj95yO5B9JEdIo3xDMtO globalClassName\\"
1073+
};
1074+
module.exports = exports;
1075+
"
1076+
`;
1077+
1078+
exports[`"modules" option should support resolving in composes preprocessor files with extensions: result 1`] = `
1079+
Array [
1080+
Array [
1081+
"../../src/index.js?[ident]!./modules/composes/values.css",
1082+
"
1083+
",
1084+
"",
1085+
],
1086+
Array [
1087+
"../../src/index.js?[ident]!./modules/composes/less-file.less",
1088+
"._3lZeyjNxPePITWh1xVieTf {
1089+
padding: 5px;
1090+
}
1091+
",
1092+
"",
1093+
],
1094+
Array [
1095+
"../../src/index.js?[ident]!./modules/composes/scss-file.scss",
1096+
"._228B9eI0iy8oD-AJowJJdF {
1097+
padding: 15px;
1098+
}
1099+
",
1100+
"",
1101+
],
1102+
Array [
1103+
"../../src/index.js?[ident]!./modules/composes/sass-file.sass",
1104+
"._2KBCbdE3L3Wax8UPzZNThX {
1105+
padding: 10px;
1106+
}
1107+
",
1108+
"",
1109+
],
1110+
Array [
1111+
"./modules/composes/composes-preprocessors.css",
1112+
".globalClassName {
1113+
color: orange;
1114+
}
1115+
1116+
._2vZioV5tEV-AlqaI8c_mtN {
1117+
color: red;
1118+
}
1119+
1120+
.YX1POP6L7ESwR7pdtyRna {
1121+
color: green;
1122+
}
1123+
1124+
._1578mz8iEiOG2qNa19R11c {
1125+
color: white;
1126+
}
1127+
1128+
._1yWiOyfH6HuDl7TOzpnWkK {
1129+
color: coral;
1130+
}
1131+
1132+
.OVj95yO5B9JEdIo3xDMtO {
1133+
background: #000;
1134+
}
1135+
",
1136+
"",
1137+
],
1138+
]
1139+
`;
1140+
1141+
exports[`"modules" option should support resolving in composes preprocessor files with extensions: warnings 1`] = `Array []`;
1142+
10451143
exports[`"modules" option should support resolving in composes: errors 1`] = `Array []`;
10461144
10471145
exports[`"modules" option should support resolving in composes: module 1`] = `
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@value v-def from './values.css';
2+
@value v-foo from './less-file.less';
3+
@value v-bar from './scss-file.scss';
4+
@value v-baz from './sass-file.sass';
5+
6+
:global(.globalClassName) {
7+
color: orange;
8+
}
9+
10+
.ghi {
11+
color: v-def;
12+
}
13+
14+
.class {
15+
color: v-foo;
16+
composes: lessClass from "less-file.less";
17+
}
18+
19+
.other {
20+
color: v-bar;
21+
composes: scssClass from "scss-file.scss";
22+
}
23+
24+
.last {
25+
color: v-baz;
26+
composes: sassClass from "sass-file.sass";
27+
}
28+
29+
.otherClassName {
30+
composes: globalClassName from global;
31+
background: #000;
32+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import css from './composes-preprocessors.css';
2+
3+
__export__ = css;
4+
5+
export default css;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@value v-def: red;
2+
@value v-foo: green;
3+
@value v-bar: white;
4+
@value v-baz: coral;
5+
6+
.lessClass {
7+
padding: 5px;
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@value v-def: red;
2+
@value v-foo: green;
3+
@value v-bar: white;
4+
@value v-baz: coral;
5+
6+
.sassClass {
7+
padding: 10px;
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@value v-def: red;
2+
@value v-foo: green;
3+
@value v-bar: white;
4+
@value v-baz: coral;
5+
6+
.scssClass {
7+
padding: 15px;
8+
}

test/modules-option.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,28 @@ describe('"modules" option', () => {
328328
expect(getErrors(stats)).toMatchSnapshot('errors');
329329
});
330330

331+
it('should support resolving in composes preprocessor files with extensions', async () => {
332+
const compiler = getCompiler(
333+
'./modules/composes/composes-preprocessors.js',
334+
{
335+
modules: {
336+
mode: 'local',
337+
exportGlobals: true,
338+
},
339+
}
340+
);
341+
const stats = await compile(compiler);
342+
343+
expect(
344+
getModuleSource('./modules/composes/composes-preprocessors.css', stats)
345+
).toMatchSnapshot('module');
346+
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
347+
'result'
348+
);
349+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
350+
expect(getErrors(stats)).toMatchSnapshot('errors');
351+
});
352+
331353
it('issue #286', async () => {
332354
const compiler = getCompiler(
333355
'./modules/issue-286/source.js',

0 commit comments

Comments
 (0)