Skip to content

Commit 5403db7

Browse files
test: pre loader
1 parent 049a280 commit 5403db7

File tree

9 files changed

+977
-419
lines changed

9 files changed

+977
-419
lines changed

package-lock.json

Lines changed: 857 additions & 323 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@
7070
"jest": "^23.4.0",
7171
"lint-staged": "^7.2.0",
7272
"memory-fs": "^0.4.1",
73-
"postcss-modules": "^1.4.1",
73+
"node-sass": "^4.9.4",
7474
"postcss-loader": "^3.0.0",
7575
"postcss-preset-env": "^6.0.6",
7676
"pre-commit": "^1.2.2",
7777
"prettier": "^1.13.7",
78+
"sass-loader": "^7.1.0",
7879
"standard-version": "^4.0.0",
7980
"strip-ansi": "^4.0.0",
8081
"webpack": "^4.16.0"

test/__snapshots__/loader.test.js.snap

Lines changed: 63 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`loader ICSS (next generation of css modules): errors 1`] = `Array []`;
4-
5-
exports[`loader ICSS (next generation of css modules): export (evaluated) 1`] = `undefined`;
6-
7-
exports[`loader ICSS (next generation of css modules): module (evaluated) 1`] = `
8-
Array [
9-
Array [
10-
1,
11-
"._button_lj5dw_1 {
12-
dispaly: block;
13-
}/* colors.css */._text-primary_1g01d_5 {
14-
color: #BF4040;
15-
}._text-secondary_1g01d_9 {
16-
color: #1F4F7F;
17-
}
18-
19-
/* my-component.css */
20-
21-
/* alias paths for other values or composition */
22-
23-
/* import multiple from a single file */
24-
25-
/* make local aliases to imported values */
26-
27-
._class_1szx8_12 {
28-
box-shadow: 0 0 10px #1F4F7F;
29-
}
30-
31-
._foo_1szx8_17 {
32-
color: red;
33-
}
34-
35-
._foo_1szx8_17 ._bar_1szx8_21 {
36-
color: yellow;
37-
}
38-
39-
.foo .bar {
40-
color: aqua;
41-
}
42-
43-
._foo_1szx8_17 .bar {
44-
color: green;
45-
}
46-
47-
.foo ._bar_1szx8_21 {
48-
color: yellowgreen;
49-
}
50-
51-
._foo_1szx8_17.bar {
52-
color: paleturquoise;
53-
}
54-
55-
._foo_1szx8_17 .bar ._baz_1szx8_41 {
56-
color: coral;
57-
}
58-
59-
._foo_1szx8_17.bar ._baz_1szx8_41 {
60-
color: lime;
61-
}
62-
",
63-
"",
64-
],
65-
]
66-
`;
67-
68-
exports[`loader ICSS (next generation of css modules): module 1`] = `
69-
"// CSS runtime
70-
module.exports = exports = require(\\"../../../src/runtime/api.js\\")(false);
71-
72-
// CSS module
73-
exports.push([module.id, \\"._button_lj5dw_1 {\\\\n dispaly: block;\\\\n}/* colors.css */._text-primary_1g01d_5 {\\\\n color: #BF4040;\\\\n}._text-secondary_1g01d_9 {\\\\n color: #1F4F7F;\\\\n}\\\\n\\\\n/* my-component.css */\\\\n\\\\n/* alias paths for other values or composition */\\\\n\\\\n/* import multiple from a single file */\\\\n\\\\n/* make local aliases to imported values */\\\\n\\\\n._class_1szx8_12 {\\\\n box-shadow: 0 0 10px #1F4F7F;\\\\n}\\\\n\\\\n._foo_1szx8_17 {\\\\n color: red;\\\\n}\\\\n\\\\n._foo_1szx8_17 ._bar_1szx8_21 {\\\\n color: yellow;\\\\n}\\\\n\\\\n.foo .bar {\\\\n color: aqua;\\\\n}\\\\n\\\\n._foo_1szx8_17 .bar {\\\\n color: green;\\\\n}\\\\n\\\\n.foo ._bar_1szx8_21 {\\\\n color: yellowgreen;\\\\n}\\\\n\\\\n._foo_1szx8_17.bar {\\\\n color: paleturquoise;\\\\n}\\\\n\\\\n._foo_1szx8_17 .bar ._baz_1szx8_41 {\\\\n color: coral;\\\\n}\\\\n\\\\n._foo_1szx8_17.bar ._baz_1szx8_41 {\\\\n color: lime;\\\\n}\\\\n\\", \\"\\"]);
74-
"
75-
`;
76-
77-
exports[`loader ICSS (next generation of css modules): warnings 1`] = `Array []`;
78-
793
exports[`loader basic (css endpoint): errors 1`] = `Array []`;
804

815
exports[`loader basic (css endpoint): escape 1`] = `
@@ -649,3 +573,66 @@ exports.push([module.id, \\":root {\\\\n --fontSize: 1rem;\\\\n --mainColor: r
649573
`;
650574

651575
exports[`loader using together with "postcss-loader" (reuse ast): warnings 1`] = `Array []`;
576+
577+
exports[`loader using together with "sass-loader": errors 1`] = `Array []`;
578+
579+
exports[`loader using together with "sass-loader": export (evaluated) 1`] = `undefined`;
580+
581+
exports[`loader using together with "sass-loader": module (evaluated) 1`] = `
582+
Array [
583+
Array [
584+
3,
585+
".other-class {
586+
color: blue;
587+
}
588+
",
589+
"",
590+
],
591+
Array [
592+
1,
593+
"body {
594+
color: white; }
595+
596+
body {
597+
font: 100% Helvetica, sans-serif;
598+
color: #333; }
599+
600+
nav ul {
601+
margin: 0;
602+
padding: 0;
603+
list-style: none; }
604+
605+
nav li {
606+
display: inline-block; }
607+
608+
nav a {
609+
display: block;
610+
padding: 6px 12px;
611+
text-decoration: none; }
612+
613+
.box {
614+
-webkit-transform: rotate(30deg);
615+
-ms-transform: rotate(30deg);
616+
transform: rotate(30deg); }
617+
618+
.background {
619+
background: url(/webpack/public/path/5b1f36bc41ab31f5b801d48ba1d65781.png); }
620+
",
621+
"",
622+
],
623+
]
624+
`;
625+
626+
exports[`loader using together with "sass-loader": module 1`] = `
627+
"// CSS runtime
628+
module.exports = exports = require(\\"../../../src/runtime/api.js\\")(false);
629+
// CSS imports
630+
var escape = require(\\"../../../src/runtime/escape.js\\");
631+
var ___CSS_LOADER_URL___0___ = escape(require(\\"./img.png\\"));
632+
exports.i(require(\\"-!../../../src/index.js??ref--4-0!./style.css\\"), \\"\\");
633+
// CSS module
634+
exports.push([module.id, \\"body {\\\\n color: white; }\\\\n\\\\nbody {\\\\n font: 100% Helvetica, sans-serif;\\\\n color: #333; }\\\\n\\\\nnav ul {\\\\n margin: 0;\\\\n padding: 0;\\\\n list-style: none; }\\\\n\\\\nnav li {\\\\n display: inline-block; }\\\\n\\\\nnav a {\\\\n display: block;\\\\n padding: 6px 12px;\\\\n text-decoration: none; }\\\\n\\\\n.box {\\\\n -webkit-transform: rotate(30deg);\\\\n -ms-transform: rotate(30deg);\\\\n transform: rotate(30deg); }\\\\n\\\\n.background {\\\\n background: url(\\" + ___CSS_LOADER_URL___0___ + \\"); }\\\\n\\", \\"\\"]);
635+
"
636+
`;
637+
638+
exports[`loader using together with "sass-loader": warnings 1`] = `Array []`;

test/fixtures/sass-loader/_reset.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
color: white;
3+
}

test/fixtures/sass-loader/basic.scss

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
$font-stack: Helvetica, sans-serif;
2+
$primary-color: #333;
3+
4+
@import 'reset';
5+
@import 'style.css';
6+
7+
body {
8+
font: 100% $font-stack;
9+
color: $primary-color;
10+
}
11+
12+
nav {
13+
ul {
14+
margin: 0;
15+
padding: 0;
16+
list-style: none;
17+
}
18+
19+
li {
20+
display: inline-block;
21+
}
22+
23+
a {
24+
display: block;
25+
padding: 6px 12px;
26+
text-decoration: none;
27+
}
28+
}
29+
30+
@mixin transform($property) {
31+
-webkit-transform: $property;
32+
-ms-transform: $property;
33+
transform: $property;
34+
}
35+
36+
.box {
37+
@include transform(rotate(30deg));
38+
}
39+
40+
.background {
41+
background: url('./img.png');
42+
}

test/fixtures/sass-loader/img.png

76.3 KB
Loading

test/fixtures/sass-loader/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.other-class {
2+
color: blue;
3+
}

test/helpers/evaluated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ function evaluated(output, modules, moduleId = 1) {
3131
const modulePath = el.identifier.split('!').pop();
3232
const importedPaths = [
3333
'',
34-
'icss',
3534
'import',
3635
'import/node_modules',
3736
'messages-api',
3837
'source-map',
3938
'url',
4039
'url/node_modules',
40+
'sass-loader',
4141
].map((importedPath) =>
4242
path.resolve(__dirname, `../fixtures/${importedPath}`, module)
4343
);

test/loader.test.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,29 +109,18 @@ describe('loader', () => {
109109
expect(stats.compilation.errors).toMatchSnapshot('errors');
110110
});
111111

112-
test('ICSS (next generation of css modules)', async () => {
112+
test('using together with "sass-loader"', async () => {
113113
const config = {
114114
rules: [
115115
{
116-
test: /\.css$/,
116+
test: /\.s[ca]ss$/i,
117117
use: [
118118
{
119119
loader: path.resolve(__dirname, '../src'),
120-
options: {
121-
importLoaders: 1,
122-
},
120+
options: {},
123121
},
124122
{
125-
loader: 'postcss-loader',
126-
options: {
127-
plugins: () => [
128-
require('postcss-modules')({
129-
// Can be 'global' or 'local',
130-
scopeBehaviour: 'local',
131-
getJSON() {},
132-
}),
133-
],
134-
},
123+
loader: 'sass-loader',
135124
},
136125
],
137126
},
@@ -143,10 +132,9 @@ describe('loader', () => {
143132
},
144133
],
145134
};
146-
const stats = await webpack('css-modules/basic.css', config);
135+
const stats = await webpack('sass-loader/basic.scss', config);
147136
const { modules } = stats.toJson();
148-
const [, module] = modules;
149-
137+
const [, , , module] = modules;
150138
const evaluatedModule = evaluated(module.source, modules);
151139

152140
expect(module.source).toMatchSnapshot('module');

0 commit comments

Comments
 (0)