Skip to content

Commit 68f72af

Browse files
authoredJul 31, 2020
feat: add module.type option, the icss option is deprecated (#1150)
1 parent 9070ba9 commit 68f72af

File tree

32 files changed

+900
-404
lines changed

32 files changed

+900
-404
lines changed
 

Diff for: ‎README.md

+41-36
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,14 @@ module.exports = {
109109

110110
## Options
111111

112-
| Name | Type | Default | Description |
113-
| :-----------------------------------: | :-------------------------: | :------------------------------------------------: | :--------------------------------------------------------------------- |
114-
| **[`url`](#url)** | `{Boolean\|Function}` | `true` | Enables/Disables `url`/`image-set` functions handling |
115-
| **[`import`](#import)** | `{Boolean\|Function}` | `true` | Enables/Disables `@import` at-rules handling |
116-
| **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `{auto: true}` | Enables/Disables CSS Modules and their configuration |
117-
| **[`icss`](#icss)** | `{Boolean}` | `true` if `modules` are enabled, `false` otherwise | Enables/Disables Interoperable CSS |
118-
| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps |
119-
| **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader |
120-
| **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax |
112+
| Name | Type | Default | Description |
113+
| :-----------------------------------: | :-------------------------: | :----------------: | :--------------------------------------------------------------------- |
114+
| **[`url`](#url)** | `{Boolean\|Function}` | `true` | Enables/Disables `url`/`image-set` functions handling |
115+
| **[`import`](#import)** | `{Boolean\|Function}` | `true` | Enables/Disables `@import` at-rules handling |
116+
| **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `{auto: true}` | Enables/Disables CSS Modules and their configuration |
117+
| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps |
118+
| **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader |
119+
| **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax |
121120

122121
### `url`
123122

@@ -526,6 +525,7 @@ module.exports = {
526525
loader: 'css-loader',
527526
options: {
528527
modules: {
528+
compileType: 'module',
529529
mode: 'local',
530530
auto: true,
531531
exportGlobals: true,
@@ -543,6 +543,38 @@ module.exports = {
543543
};
544544
```
545545

546+
##### `compileType`
547+
548+
Type: `'module' | 'icss'`
549+
Default: `'module'`
550+
551+
Controls the level of compilation applied to the input styles.
552+
553+
The `module` handles `class` and `id` scoping and `@value` values.
554+
The `icss` will only compile the low level `Interoperable CSS` format for declaring `:import` and `:export` dependencies between CSS and other languages.
555+
556+
ICSS underpins CSS Module support, and provides a low level syntax for other tools to implement CSS-module variations of their own.
557+
558+
**webpack.config.js**
559+
560+
```js
561+
module.exports = {
562+
module: {
563+
rules: [
564+
{
565+
test: /\.css$/i,
566+
loader: 'css-loader',
567+
options: {
568+
modules: {
569+
compileType: 'icss',
570+
},
571+
},
572+
},
573+
],
574+
},
575+
};
576+
```
577+
546578
##### `auto`
547579

548580
Type: `Boolean|RegExp|Function`
@@ -1001,33 +1033,6 @@ module.exports = {
10011033
};
10021034
```
10031035

1004-
### `icss`
1005-
1006-
Type: Boolean Default: `true` if `modules` are enabled, false otherwise
1007-
1008-
Enables/disables handling of the low level "Interoperable CSS" format for declaring
1009-
import and export dependencies between CSS and other languages. ICSS enables
1010-
CSS Module support, and is enabled automatically when `modules` are enabled. It
1011-
can also be enabled independently to allow other loaders to handle processing CSS modules.
1012-
1013-
**webpack.config.js**
1014-
1015-
```js
1016-
module.exports = {
1017-
module: {
1018-
rules: [
1019-
{
1020-
test: /\.css$/i,
1021-
loader: 'css-loader',
1022-
options: {
1023-
icss: true,
1024-
},
1025-
},
1026-
],
1027-
},
1028-
};
1029-
```
1030-
10311036
### `sourceMap`
10321037

10331038
Type: `Boolean`

Diff for: ‎src/index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
shouldUseModulesPlugins,
1818
shouldUseImportPlugin,
1919
shouldUseURLPlugin,
20+
shouldUseIcssPlugin,
2021
getPreRequester,
2122
getExportCode,
2223
getFilter,
@@ -51,9 +52,7 @@ export default async function loader(content, map, meta) {
5152
const replacements = [];
5253
const exports = [];
5354

54-
const needUseModulesPlugins = shouldUseModulesPlugins(options);
55-
56-
if (needUseModulesPlugins) {
55+
if (shouldUseModulesPlugins(options)) {
5756
plugins.push(...getModulesPlugins(options, this));
5857
}
5958

@@ -112,7 +111,7 @@ export default async function loader(content, map, meta) {
112111
const icssPluginImports = [];
113112
const icssPluginApi = [];
114113

115-
if (needUseModulesPlugins || options.icss) {
114+
if (shouldUseIcssPlugin(options)) {
116115
const icssResolver = this.getResolve({
117116
conditionNames: ['style'],
118117
extensions: [],

Diff for: ‎src/options.json

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
"type": "object",
3737
"additionalProperties": false,
3838
"properties": {
39+
"compileType": {
40+
"description": "Controls the extent to which css-loader will process module code (https://github.com/webpack-contrib/css-loader#type)",
41+
"enum": ["module", "icss"]
42+
},
3943
"auto": {
4044
"description": "Allows auto enable CSS modules based on filename (https://github.com/webpack-contrib/css-loader#auto).",
4145
"anyOf": [

Diff for: ‎src/utils.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ function getModulesOptions(rawOptions, loaderContext) {
125125
}
126126

127127
let modulesOptions = {
128+
compileType: rawOptions.icss ? 'icss' : 'module',
128129
auto: true,
129130
mode: 'local',
130131
exportGlobals: false,
@@ -201,12 +202,22 @@ function getModulesOptions(rawOptions, loaderContext) {
201202
}
202203

203204
function normalizeOptions(rawOptions, loaderContext) {
205+
if (rawOptions.icss) {
206+
loaderContext.emitWarning(
207+
new Error(
208+
'The "icss" option is deprecated, use "modules.compileType: "icss"" instead'
209+
)
210+
);
211+
}
212+
204213
const modulesOptions = getModulesOptions(rawOptions, loaderContext);
214+
205215
return {
206216
url: typeof rawOptions.url === 'undefined' ? true : rawOptions.url,
207217
import: typeof rawOptions.import === 'undefined' ? true : rawOptions.import,
208218
modules: modulesOptions,
209-
icss: modulesOptions ? true : rawOptions.icss,
219+
// TODO remove in the next major release
220+
icss: typeof rawOptions.icss === 'undefined' ? false : rawOptions.icss,
210221
sourceMap:
211222
typeof rawOptions.sourceMap === 'boolean'
212223
? rawOptions.sourceMap
@@ -242,7 +253,11 @@ function shouldUseURLPlugin(options) {
242253
}
243254

244255
function shouldUseModulesPlugins(options) {
245-
return Boolean(options.modules);
256+
return options.modules.compileType === 'module';
257+
}
258+
259+
function shouldUseIcssPlugin(options) {
260+
return options.icss === true || Boolean(options.modules);
246261
}
247262

248263
function getModulesPlugins(options, loaderContext) {
@@ -545,6 +560,7 @@ export {
545560
shouldUseModulesPlugins,
546561
shouldUseImportPlugin,
547562
shouldUseURLPlugin,
563+
shouldUseIcssPlugin,
548564
normalizeUrl,
549565
requestify,
550566
getFilter,

Diff for: ‎test/__snapshots__/icss.test.js.snap

-313
This file was deleted.

Diff for: ‎test/__snapshots__/modules-option.test.js.snap

+700
Large diffs are not rendered by default.

Diff for: ‎test/__snapshots__/validate-options.test.js.snap

+21-14
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ exports[`validate options should throw an error on the "importLoaders" option wi
5151
exports[`validate options should throw an error on the "modules" option with "{"auto":"invalid"}" value 1`] = `
5252
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
5353
- options.modules should be one of these:
54-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
54+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
5555
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
5656
Details:
5757
* options.modules.auto should be one of these:
@@ -63,6 +63,13 @@ exports[`validate options should throw an error on the "modules" option with "{"
6363
* options.modules.auto should be a boolean."
6464
`;
6565
66+
exports[`validate options should throw an error on the "modules" option with "{"compileType":"unknown"}" value 1`] = `
67+
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
68+
- options.modules.compileType should be one of these:
69+
\\"module\\" | \\"icss\\"
70+
-> Controls the extent to which css-loader will process module code (https://github.com/webpack-contrib/css-loader#type)"
71+
`;
72+
6673
exports[`validate options should throw an error on the "modules" option with "{"exportGlobals":"invalid"}" value 1`] = `
6774
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
6875
- options.modules.exportGlobals should be a boolean.
@@ -109,7 +116,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
109116
exports[`validate options should throw an error on the "modules" option with "{"localIdentRegExp":true}" value 1`] = `
110117
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
111118
- options.modules should be one of these:
112-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
119+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
113120
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
114121
Details:
115122
* options.modules.localIdentRegExp should be one of these:
@@ -123,7 +130,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
123130
exports[`validate options should throw an error on the "modules" option with "{"mode":"globals"}" value 1`] = `
124131
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
125132
- options.modules should be one of these:
126-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
133+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
127134
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
128135
Details:
129136
* options.modules.mode should be one of these:
@@ -138,7 +145,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
138145
exports[`validate options should throw an error on the "modules" option with "{"mode":"locals"}" value 1`] = `
139146
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
140147
- options.modules should be one of these:
141-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
148+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
142149
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
143150
Details:
144151
* options.modules.mode should be one of these:
@@ -153,7 +160,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
153160
exports[`validate options should throw an error on the "modules" option with "{"mode":"pures"}" value 1`] = `
154161
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
155162
- options.modules should be one of these:
156-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
163+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
157164
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
158165
Details:
159166
* options.modules.mode should be one of these:
@@ -168,7 +175,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
168175
exports[`validate options should throw an error on the "modules" option with "{"mode":true}" value 1`] = `
169176
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
170177
- options.modules should be one of these:
171-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
178+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
172179
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
173180
Details:
174181
* options.modules.mode should be one of these:
@@ -189,53 +196,53 @@ exports[`validate options should throw an error on the "modules" option with "{"
189196
exports[`validate options should throw an error on the "modules" option with "globals" value 1`] = `
190197
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
191198
- options.modules should be one of these:
192-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
199+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
193200
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
194201
Details:
195202
* options.modules should be a boolean.
196203
* options.modules should be one of these:
197204
\\"local\\" | \\"global\\" | \\"pure\\"
198205
* options.modules should be an object:
199-
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
206+
object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
200207
`;
201208
202209
exports[`validate options should throw an error on the "modules" option with "locals" value 1`] = `
203210
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
204211
- options.modules should be one of these:
205-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
212+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
206213
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
207214
Details:
208215
* options.modules should be a boolean.
209216
* options.modules should be one of these:
210217
\\"local\\" | \\"global\\" | \\"pure\\"
211218
* options.modules should be an object:
212-
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
219+
object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
213220
`;
214221
215222
exports[`validate options should throw an error on the "modules" option with "pures" value 1`] = `
216223
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
217224
- options.modules should be one of these:
218-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
225+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
219226
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
220227
Details:
221228
* options.modules should be a boolean.
222229
* options.modules should be one of these:
223230
\\"local\\" | \\"global\\" | \\"pure\\"
224231
* options.modules should be an object:
225-
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
232+
object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
226233
`;
227234
228235
exports[`validate options should throw an error on the "modules" option with "true" value 1`] = `
229236
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
230237
- options.modules should be one of these:
231-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
238+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
232239
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
233240
Details:
234241
* options.modules should be a boolean.
235242
* options.modules should be one of these:
236243
\\"local\\" | \\"global\\" | \\"pure\\"
237244
* options.modules should be an object:
238-
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
245+
object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
239246
`;
240247
241248
exports[`validate options should throw an error on the "sourceMap" option with "true" value 1`] = `

Diff for: ‎test/icss.test.js

-35
This file was deleted.

Diff for: ‎test/modules-option.test.js

+110
Original file line numberDiff line numberDiff line change
@@ -1166,4 +1166,114 @@ describe('"modules" option', () => {
11661166
expect(getWarnings(stats)).toMatchSnapshot('warnings');
11671167
expect(getErrors(stats)).toMatchSnapshot('errors');
11681168
});
1169+
1170+
const icssTestCasesPath = path.join(
1171+
__dirname,
1172+
'fixtures/modules/icss/tests-cases'
1173+
);
1174+
const icssTestCases = fs.readdirSync(icssTestCasesPath);
1175+
1176+
icssTestCases.forEach((name) => {
1177+
it(`show work with the "compileType" option, case "${name}"`, async () => {
1178+
const compiler = getCompiler(
1179+
`./modules/icss/tests-cases/${name}/source.js`,
1180+
{
1181+
modules: {
1182+
compileType: 'icss',
1183+
},
1184+
}
1185+
);
1186+
const stats = await compile(compiler);
1187+
1188+
expect(
1189+
getModuleSource(`./modules/icss/tests-cases/${name}/source.css`, stats)
1190+
).toMatchSnapshot('module');
1191+
expect(
1192+
getExecutedCode('main.bundle.js', compiler, stats)
1193+
).toMatchSnapshot('result');
1194+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
1195+
expect(getErrors(stats)).toMatchSnapshot('errors');
1196+
});
1197+
});
1198+
1199+
it('show work and warn about the "icss" option deprecation', async () => {
1200+
const compiler = getCompiler(
1201+
'./modules/icss/tests-cases/import/source.js',
1202+
{
1203+
icss: true,
1204+
}
1205+
);
1206+
const stats = await compile(compiler);
1207+
1208+
expect(
1209+
getModuleSource('./modules/icss/tests-cases/import/source.css', stats)
1210+
).toMatchSnapshot('module');
1211+
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
1212+
'result'
1213+
);
1214+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
1215+
expect(getErrors(stats)).toMatchSnapshot('errors');
1216+
});
1217+
1218+
it('show work with the "compileType" and "exportOnlyLocals" options', async () => {
1219+
const compiler = getCompiler(
1220+
'./modules/icss/tests-cases/import/source.js',
1221+
{
1222+
modules: {
1223+
compileType: 'icss',
1224+
exportOnlyLocals: true,
1225+
},
1226+
}
1227+
);
1228+
const stats = await compile(compiler);
1229+
1230+
expect(
1231+
getModuleSource('./modules/icss/tests-cases/import/source.css', stats)
1232+
).toMatchSnapshot('module');
1233+
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
1234+
'result'
1235+
);
1236+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
1237+
expect(getErrors(stats)).toMatchSnapshot('errors');
1238+
});
1239+
1240+
it('show work with the "compileType" and "namedExport" options', async () => {
1241+
const compiler = getCompiler(
1242+
'./modules/icss/tests-cases/import/source.js',
1243+
{
1244+
modules: {
1245+
compileType: 'icss',
1246+
namedExport: true,
1247+
},
1248+
}
1249+
);
1250+
const stats = await compile(compiler);
1251+
1252+
expect(
1253+
getModuleSource('./modules/icss/tests-cases/import/source.css', stats)
1254+
).toMatchSnapshot('module');
1255+
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
1256+
'result'
1257+
);
1258+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
1259+
expect(getErrors(stats)).toMatchSnapshot('errors');
1260+
});
1261+
1262+
it('show work with the "compileType" option using the "module" value', async () => {
1263+
const compiler = getCompiler('./modules/composes/composes.js', {
1264+
modules: {
1265+
compileType: 'module',
1266+
},
1267+
});
1268+
const stats = await compile(compiler);
1269+
1270+
expect(
1271+
getModuleSource('./modules/composes/composes.css', stats)
1272+
).toMatchSnapshot('module');
1273+
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
1274+
'result'
1275+
);
1276+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
1277+
expect(getErrors(stats)).toMatchSnapshot('errors');
1278+
});
11691279
});

Diff for: ‎test/validate-options.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ describe('validate options', () => {
2121
'global',
2222
'local',
2323
'pure',
24+
{ compileType: 'module' },
25+
{ compileType: 'icss' },
2426
{ mode: 'global' },
2527
{ mode: 'local' },
2628
{ mode: 'pure' },
@@ -54,6 +56,7 @@ describe('validate options', () => {
5456
'globals',
5557
'locals',
5658
'pures',
59+
{ compileType: 'unknown' },
5760
{ mode: true },
5861
{ mode: 'globals' },
5962
{ mode: 'locals' },

0 commit comments

Comments
 (0)
Please sign in to comment.