Skip to content

Commit 505726d

Browse files
refactor: removed compileType option in favor mode option (webpack-contrib#1302)
1 parent 8a0c87b commit 505726d

File tree

6 files changed

+97
-92
lines changed

6 files changed

+97
-92
lines changed

README.md

+13-39
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ module.exports = {
576576
loader: "css-loader",
577577
options: {
578578
modules: {
579-
compileType: "module",
580579
mode: "local",
581580
auto: true,
582581
exportGlobals: true,
@@ -594,38 +593,6 @@ module.exports = {
594593
};
595594
```
596595

597-
##### `compileType`
598-
599-
Type: `'module' | 'icss'`
600-
Default: `'module'`
601-
602-
Controls the level of compilation applied to the input styles.
603-
604-
The `module` handles `class` and `id` scoping and `@value` values.
605-
The `icss` will only compile the low level `Interoperable CSS` format for declaring `:import` and `:export` dependencies between CSS and other languages.
606-
607-
ICSS underpins CSS Module support, and provides a low level syntax for other tools to implement CSS-module variations of their own.
608-
609-
**webpack.config.js**
610-
611-
```js
612-
module.exports = {
613-
module: {
614-
rules: [
615-
{
616-
test: /\.css$/i,
617-
loader: "css-loader",
618-
options: {
619-
modules: {
620-
compileType: "icss",
621-
},
622-
},
623-
},
624-
],
625-
},
626-
};
627-
```
628-
629596
##### `auto`
630597

631598
Type: `Boolean|RegExp|Function`
@@ -637,7 +604,7 @@ Allows auto enable CSS modules based on filename.
637604

638605
Possible values:
639606

640-
- `true` - enables CSS modules or interoperable CSS format, sets the [`modules.compileType`](#compiletype) option to `module` value for all files which satisfy `/\.module(s)?\.\w+$/i.test(filename)` condition or sets the [`modules.compileType`](#compiletype) option to `icss` value for all files which satisfy `/\.icss\.\w+$/i.test(filename)` condition
607+
- `true` - enables CSS modules or interoperable CSS format, sets the [`modules.mode`](#mode) option to `local` value for all files which satisfy `/\.module(s)?\.\w+$/i.test(filename)` condition or sets the [`modules.mode`](#mode) option to `icss` value for all files which satisfy `/\.icss\.\w+$/i.test(filename)` condition
641608
- `false` - disables CSS modules or interoperable CSS format based on filename
642609

643610
**webpack.config.js**
@@ -715,9 +682,16 @@ Default: `'local'`
715682

716683
Setup `mode` option. You can omit the value when you want `local` mode.
717684

685+
Controls the level of compilation applied to the input styles.
686+
687+
The `local`, `global`, and `pure` handles `class` and `id` scoping and `@value` values.
688+
The `icss` will only compile the low level `Interoperable CSS` format for declaring `:import` and `:export` dependencies between CSS and other languages.
689+
690+
ICSS underpins CSS Module support, and provides a low level syntax for other tools to implement CSS-module variations of their own.
691+
718692
###### `String`
719693

720-
Possible values - `local`, `global`, and `pure`.
694+
Possible values - `local`, `global`, `pure`, and `icss`.
721695

722696
**webpack.config.js**
723697

@@ -743,7 +717,7 @@ module.exports = {
743717

744718
Allows set different values for the `mode` option based on a filename
745719

746-
Possible return values - `local`, `global`, and `pure`.
720+
Possible return values - `local`, `global`, `pure` and `icss`.
747721

748722
**webpack.config.js**
749723

@@ -1343,7 +1317,7 @@ module.exports = {
13431317

13441318
### Separating `Interoperable CSS`-only and `CSS Module` features
13451319

1346-
The following setup is an example of allowing `Interoperable CSS` features only (such as `:import` and `:export`) without using further `CSS Module` functionality by setting `compileType` option for all files that do not match `*.module.scss` naming convention. This is for reference as having `ICSS` features applied to all files was default `css-loader` behavior before v4.
1320+
The following setup is an example of allowing `Interoperable CSS` features only (such as `:import` and `:export`) without using further `CSS Module` functionality by setting `mode` option for all files that do not match `*.module.scss` naming convention. This is for reference as having `ICSS` features applied to all files was default `css-loader` behavior before v4.
13471321
Meanwhile all files matching `*.module.scss` are treated as `CSS Modules` in this example.
13481322

13491323
An example case is assumed where a project requires canvas drawing variables to be synchronized with CSS - canvas drawing uses the same color (set by color name in JavaScript) as HTML background (set by class name in CSS).
@@ -1369,7 +1343,7 @@ module.exports = {
13691343
options: {
13701344
importLoaders: 1,
13711345
modules: {
1372-
compileType: 'icss'
1346+
mode: 'icss'
13731347
}
13741348
}
13751349
},
@@ -1391,7 +1365,7 @@ module.exports = {
13911365
options: {
13921366
importLoaders: 1,
13931367
modules: {
1394-
compileType: 'module'
1368+
mode: 'local'
13951369
}
13961370
}
13971371
},

src/options.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@
5757
"type": "boolean"
5858
},
5959
{
60-
"enum": ["local", "global", "pure"]
60+
"enum": ["local", "global", "pure", "icss"]
6161
},
6262
{
6363
"type": "object",
6464
"additionalProperties": false,
6565
"properties": {
66-
"compileType": {
67-
"description": "Controls the extent to which css-loader will process module code (https://github.com/webpack-contrib/css-loader#type)",
68-
"enum": ["module", "icss"]
69-
},
7066
"auto": {
7167
"description": "Allows auto enable CSS modules based on filename (https://github.com/webpack-contrib/css-loader#auto).",
7268
"anyOf": [
@@ -85,7 +81,7 @@
8581
"description": "Setup `mode` option (https://github.com/webpack-contrib/css-loader#mode).",
8682
"anyOf": [
8783
{
88-
"enum": ["local", "global", "pure"]
84+
"enum": ["local", "global", "pure", "icss"]
8985
},
9086
{
9187
"instanceof": "Function"

src/utils.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,8 @@ function getModulesOptions(rawOptions, loaderContext) {
421421
}
422422

423423
let modulesOptions = {
424-
compileType: isIcss ? "icss" : "module",
425424
auto: true,
426-
mode: "local",
425+
mode: isIcss ? "icss" : "local",
427426
exportGlobals: false,
428427
localIdentName: "[hash:base64]",
429428
localIdentContext: loaderContext.rootContext,
@@ -548,7 +547,11 @@ function shouldUseURLPlugin(options) {
548547
}
549548

550549
function shouldUseModulesPlugins(options) {
551-
return options.modules.compileType === "module";
550+
if (typeof options.modules === "boolean" && options.modules === false) {
551+
return false;
552+
}
553+
554+
return options.modules.mode !== "icss";
552555
}
553556

554557
function shouldUseIcssPlugin(options) {

0 commit comments

Comments
 (0)