Skip to content

Commit 1167ab4

Browse files
refactor: removed compileType option in favor mode option (webpack-contrib#1302)
1 parent 1c3d9ad commit 1167ab4

File tree

7 files changed

+781
-152
lines changed

7 files changed

+781
-152
lines changed

README.md

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ module.exports = {
577577
loader: "css-loader",
578578
options: {
579579
modules: {
580-
compileType: "module",
581580
mode: "local",
582581
auto: true,
583582
exportGlobals: true,
@@ -595,38 +594,6 @@ module.exports = {
595594
};
596595
```
597596

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

632599
Type: `Boolean|RegExp|Function`
@@ -638,7 +605,7 @@ Allows auto enable CSS modules based on filename.
638605

639606
Possible values:
640607

641-
- `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
608+
- `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
642609
- `false` - disables CSS modules or interoperable CSS format based on filename
643610

644611
**webpack.config.js**
@@ -716,9 +683,16 @@ Default: `'local'`
716683

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

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

721-
Possible values - `local`, `global`, and `pure`.
695+
Possible values - `local`, `global`, `pure`, and `icss`.
722696

723697
**webpack.config.js**
724698

@@ -744,7 +718,7 @@ module.exports = {
744718

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

747-
Possible return values - `local`, `global`, and `pure`.
721+
Possible return values - `local`, `global`, `pure` and `icss`.
748722

749723
**webpack.config.js**
750724

@@ -1312,7 +1286,7 @@ module.exports = {
13121286

13131287
### Separating `Interoperable CSS`-only and `CSS Module` features
13141288

1315-
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.
1289+
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.
13161290
Meanwhile all files matching `*.module.scss` are treated as `CSS Modules` in this example.
13171291

13181292
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).
@@ -1338,7 +1312,7 @@ module.exports = {
13381312
options: {
13391313
importLoaders: 1,
13401314
modules: {
1341-
compileType: 'icss'
1315+
mode: 'icss'
13421316
}
13431317
}
13441318
},
@@ -1360,7 +1334,7 @@ module.exports = {
13601334
options: {
13611335
importLoaders: 1,
13621336
modules: {
1363-
compileType: 'module'
1337+
mode: 'local'
13641338
}
13651339
}
13661340
},

src/options.json

Lines changed: 2 additions & 6 deletions
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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,8 @@ function getModulesOptions(rawOptions, loaderContext) {
358358
}
359359

360360
let modulesOptions = {
361-
compileType: isIcss ? "icss" : "module",
362361
auto: true,
363-
mode: "local",
362+
mode: isIcss ? "icss" : "local",
364363
exportGlobals: false,
365364
localIdentName: "[hash:base64]",
366365
localIdentContext: loaderContext.rootContext,
@@ -485,7 +484,11 @@ function shouldUseURLPlugin(options) {
485484
}
486485

487486
function shouldUseModulesPlugins(options) {
488-
return options.modules.compileType === "module";
487+
if (typeof options.modules === "boolean" && options.modules === false) {
488+
return false;
489+
}
490+
491+
return options.modules.mode !== "icss";
489492
}
490493

491494
function shouldUseIcssPlugin(options) {

0 commit comments

Comments
 (0)