Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: webpack-contrib/css-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.1.1
Choose a base ref
...
head repository: webpack-contrib/css-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.2.0
Choose a head ref
  • 2 commits
  • 35 files changed
  • 2 contributors

Commits on Jul 31, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    68f72af View commit details
  2. chore(release): 4.2.0

    alexander-akait committed Jul 31, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d24f9c7 View commit details
Showing with 909 additions and 406 deletions.
  1. +7 −0 CHANGELOG.md
  2. +41 −36 README.md
  3. +1 −1 package-lock.json
  4. +1 −1 package.json
  5. +3 −4 src/index.js
  6. +4 −0 src/options.json
  7. +18 −2 src/utils.js
  8. +0 −313 test/__snapshots__/icss.test.js.snap
  9. +700 −0 test/__snapshots__/modules-option.test.js.snap
  10. +21 −14 test/__snapshots__/validate-options.test.js.snap
  11. 0 test/fixtures/{ → modules}/icss/tests-cases/duplicate-export-in-multiple-export/source.css
  12. 0 test/fixtures/{ → modules}/icss/tests-cases/duplicate-export-in-multiple-export/source.js
  13. 0 test/fixtures/{ → modules}/icss/tests-cases/duplicate-export/source.css
  14. 0 test/fixtures/{ → modules}/icss/tests-cases/duplicate-export/source.js
  15. 0 test/fixtures/{ → modules}/icss/tests-cases/empty-export/source.css
  16. 0 test/fixtures/{ → modules}/icss/tests-cases/empty-export/source.js
  17. 0 test/fixtures/{ → modules}/icss/tests-cases/empty-import/source.css
  18. 0 test/fixtures/{ → modules}/icss/tests-cases/empty-import/source.js
  19. 0 test/fixtures/{ → modules}/icss/tests-cases/export-reserved-keywords/source.css
  20. 0 test/fixtures/{ → modules}/icss/tests-cases/export-reserved-keywords/source.js
  21. 0 test/fixtures/{ → modules}/icss/tests-cases/export/source.css
  22. 0 test/fixtures/{ → modules}/icss/tests-cases/export/source.js
  23. 0 test/fixtures/{ → modules}/icss/tests-cases/import-reserved-keywords/source.css
  24. 0 test/fixtures/{ → modules}/icss/tests-cases/import-reserved-keywords/source.js
  25. 0 test/fixtures/{ → modules}/icss/tests-cases/import-reserved-keywords/vars.css
  26. 0 test/fixtures/{ → modules}/icss/tests-cases/import/source.css
  27. 0 test/fixtures/{ → modules}/icss/tests-cases/import/source.js
  28. 0 test/fixtures/{ → modules}/icss/tests-cases/import/vars.css
  29. 0 test/fixtures/{ → modules}/icss/tests-cases/multiple-export/source.css
  30. 0 test/fixtures/{ → modules}/icss/tests-cases/multiple-export/source.js
  31. 0 test/fixtures/{ → modules}/icss/tests-cases/multiple-keys-values-in-export/source.css
  32. 0 test/fixtures/{ → modules}/icss/tests-cases/multiple-keys-values-in-export/source.js
  33. +0 −35 test/icss.test.js
  34. +110 −0 test/modules-option.test.js
  35. +3 −0 test/validate-options.test.js
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [4.2.0](https://github.com/webpack-contrib/css-loader/compare/v4.1.1...v4.2.0) (2020-07-31)


### Features

* add `module.type` option, the `icss` option is deprecated ([#1150](https://github.com/webpack-contrib/css-loader/issues/1150)) ([68f72af](https://github.com/webpack-contrib/css-loader/commit/68f72af2a09111f74dcacbf7af019fe7eb40cb6c))

### [4.1.1](https://github.com/webpack-contrib/css-loader/compare/v4.1.0...v4.1.1) (2020-07-30)


77 changes: 41 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -109,15 +109,14 @@ module.exports = {

## Options

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

### `url`

@@ -526,6 +525,7 @@ module.exports = {
loader: 'css-loader',
options: {
modules: {
compileType: 'module',
mode: 'local',
auto: true,
exportGlobals: true,
@@ -543,6 +543,38 @@ module.exports = {
};
```

##### `compileType`

Type: `'module' | 'icss'`
Default: `'module'`

Controls the level of compilation applied to the input styles.

The `module` handles `class` and `id` scoping and `@value` values.
The `icss` will only compile the low level `Interoperable CSS` format for declaring `:import` and `:export` dependencies between CSS and other languages.

ICSS underpins CSS Module support, and provides a low level syntax for other tools to implement CSS-module variations of their own.

**webpack.config.js**

```js
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
loader: 'css-loader',
options: {
modules: {
compileType: 'icss',
},
},
},
],
},
};
```

##### `auto`

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

### `icss`

Type: Boolean Default: `true` if `modules` are enabled, false otherwise

Enables/disables handling of the low level "Interoperable CSS" format for declaring
import and export dependencies between CSS and other languages. ICSS enables
CSS Module support, and is enabled automatically when `modules` are enabled. It
can also be enabled independently to allow other loaders to handle processing CSS modules.

**webpack.config.js**

```js
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
loader: 'css-loader',
options: {
icss: true,
},
},
],
},
};
```

### `sourceMap`

Type: `Boolean`
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "css-loader",
"version": "4.1.1",
"version": "4.2.0",
"description": "css loader module for webpack",
"license": "MIT",
"repository": "webpack-contrib/css-loader",
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import {
shouldUseModulesPlugins,
shouldUseImportPlugin,
shouldUseURLPlugin,
shouldUseIcssPlugin,
getPreRequester,
getExportCode,
getFilter,
@@ -51,9 +52,7 @@ export default async function loader(content, map, meta) {
const replacements = [];
const exports = [];

const needUseModulesPlugins = shouldUseModulesPlugins(options);

if (needUseModulesPlugins) {
if (shouldUseModulesPlugins(options)) {
plugins.push(...getModulesPlugins(options, this));
}

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

if (needUseModulesPlugins || options.icss) {
if (shouldUseIcssPlugin(options)) {
const icssResolver = this.getResolve({
conditionNames: ['style'],
extensions: [],
4 changes: 4 additions & 0 deletions src/options.json
Original file line number Diff line number Diff line change
@@ -36,6 +36,10 @@
"type": "object",
"additionalProperties": false,
"properties": {
"compileType": {
"description": "Controls the extent to which css-loader will process module code (https://github.com/webpack-contrib/css-loader#type)",
"enum": ["module", "icss"]
},
"auto": {
"description": "Allows auto enable CSS modules based on filename (https://github.com/webpack-contrib/css-loader#auto).",
"anyOf": [
20 changes: 18 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -125,6 +125,7 @@ function getModulesOptions(rawOptions, loaderContext) {
}

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

function normalizeOptions(rawOptions, loaderContext) {
if (rawOptions.icss) {
loaderContext.emitWarning(
new Error(
'The "icss" option is deprecated, use "modules.compileType: "icss"" instead'
)
);
}

const modulesOptions = getModulesOptions(rawOptions, loaderContext);

return {
url: typeof rawOptions.url === 'undefined' ? true : rawOptions.url,
import: typeof rawOptions.import === 'undefined' ? true : rawOptions.import,
modules: modulesOptions,
icss: modulesOptions ? true : rawOptions.icss,
// TODO remove in the next major release
icss: typeof rawOptions.icss === 'undefined' ? false : rawOptions.icss,
sourceMap:
typeof rawOptions.sourceMap === 'boolean'
? rawOptions.sourceMap
@@ -242,7 +253,11 @@ function shouldUseURLPlugin(options) {
}

function shouldUseModulesPlugins(options) {
return Boolean(options.modules);
return options.modules.compileType === 'module';
}

function shouldUseIcssPlugin(options) {
return options.icss === true || Boolean(options.modules);
}

function getModulesPlugins(options, loaderContext) {
@@ -545,6 +560,7 @@ export {
shouldUseModulesPlugins,
shouldUseImportPlugin,
shouldUseURLPlugin,
shouldUseIcssPlugin,
normalizeUrl,
requestify,
getFilter,
313 changes: 0 additions & 313 deletions test/__snapshots__/icss.test.js.snap

This file was deleted.

700 changes: 700 additions & 0 deletions test/__snapshots__/modules-option.test.js.snap

Large diffs are not rendered by default.

35 changes: 21 additions & 14 deletions test/__snapshots__/validate-options.test.js.snap
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ exports[`validate options should throw an error on the "importLoaders" option wi
exports[`validate options should throw an error on the "modules" option with "{"auto":"invalid"}" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.auto should be one of these:
@@ -63,6 +63,13 @@ exports[`validate options should throw an error on the "modules" option with "{"
* options.modules.auto should be a boolean."
`;
exports[`validate options should throw an error on the "modules" option with "{"compileType":"unknown"}" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules.compileType should be one of these:
\\"module\\" | \\"icss\\"
-> Controls the extent to which css-loader will process module code (https://github.com/webpack-contrib/css-loader#type)"
`;
exports[`validate options should throw an error on the "modules" option with "{"exportGlobals":"invalid"}" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules.exportGlobals should be a boolean.
@@ -109,7 +116,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
exports[`validate options should throw an error on the "modules" option with "{"localIdentRegExp":true}" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.localIdentRegExp should be one of these:
@@ -123,7 +130,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
exports[`validate options should throw an error on the "modules" option with "{"mode":"globals"}" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.mode should be one of these:
@@ -138,7 +145,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
exports[`validate options should throw an error on the "modules" option with "{"mode":"locals"}" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.mode should be one of these:
@@ -153,7 +160,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
exports[`validate options should throw an error on the "modules" option with "{"mode":"pures"}" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.mode should be one of these:
@@ -168,7 +175,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
exports[`validate options should throw an error on the "modules" option with "{"mode":true}" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.mode should be one of these:
@@ -189,53 +196,53 @@ exports[`validate options should throw an error on the "modules" option with "{"
exports[`validate options should throw an error on the "modules" option with "globals" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules should be a boolean.
* options.modules should be one of these:
\\"local\\" | \\"global\\" | \\"pure\\"
* options.modules should be an object:
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
`;
exports[`validate options should throw an error on the "modules" option with "locals" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules should be a boolean.
* options.modules should be one of these:
\\"local\\" | \\"global\\" | \\"pure\\"
* options.modules should be an object:
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
`;
exports[`validate options should throw an error on the "modules" option with "pures" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules should be a boolean.
* options.modules should be one of these:
\\"local\\" | \\"global\\" | \\"pure\\"
* options.modules should be an object:
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
`;
exports[`validate options should throw an error on the "modules" option with "true" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules should be a boolean.
* options.modules should be one of these:
\\"local\\" | \\"global\\" | \\"pure\\"
* options.modules should be an object:
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
object { compileType?, auto?, mode?, localIdentName?, localIdentContext?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
`;
exports[`validate options should throw an error on the "sourceMap" option with "true" value 1`] = `
35 changes: 0 additions & 35 deletions test/icss.test.js

This file was deleted.

110 changes: 110 additions & 0 deletions test/modules-option.test.js
Original file line number Diff line number Diff line change
@@ -1166,4 +1166,114 @@ describe('"modules" option', () => {
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

const icssTestCasesPath = path.join(
__dirname,
'fixtures/modules/icss/tests-cases'
);
const icssTestCases = fs.readdirSync(icssTestCasesPath);

icssTestCases.forEach((name) => {
it(`show work with the "compileType" option, case "${name}"`, async () => {
const compiler = getCompiler(
`./modules/icss/tests-cases/${name}/source.js`,
{
modules: {
compileType: 'icss',
},
}
);
const stats = await compile(compiler);

expect(
getModuleSource(`./modules/icss/tests-cases/${name}/source.css`, stats)
).toMatchSnapshot('module');
expect(
getExecutedCode('main.bundle.js', compiler, stats)
).toMatchSnapshot('result');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});
});

it('show work and warn about the "icss" option deprecation', async () => {
const compiler = getCompiler(
'./modules/icss/tests-cases/import/source.js',
{
icss: true,
}
);
const stats = await compile(compiler);

expect(
getModuleSource('./modules/icss/tests-cases/import/source.css', stats)
).toMatchSnapshot('module');
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
'result'
);
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('show work with the "compileType" and "exportOnlyLocals" options', async () => {
const compiler = getCompiler(
'./modules/icss/tests-cases/import/source.js',
{
modules: {
compileType: 'icss',
exportOnlyLocals: true,
},
}
);
const stats = await compile(compiler);

expect(
getModuleSource('./modules/icss/tests-cases/import/source.css', stats)
).toMatchSnapshot('module');
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
'result'
);
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('show work with the "compileType" and "namedExport" options', async () => {
const compiler = getCompiler(
'./modules/icss/tests-cases/import/source.js',
{
modules: {
compileType: 'icss',
namedExport: true,
},
}
);
const stats = await compile(compiler);

expect(
getModuleSource('./modules/icss/tests-cases/import/source.css', stats)
).toMatchSnapshot('module');
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
'result'
);
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('show work with the "compileType" option using the "module" value', async () => {
const compiler = getCompiler('./modules/composes/composes.js', {
modules: {
compileType: 'module',
},
});
const stats = await compile(compiler);

expect(
getModuleSource('./modules/composes/composes.css', stats)
).toMatchSnapshot('module');
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
'result'
);
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});
});
3 changes: 3 additions & 0 deletions test/validate-options.test.js
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ describe('validate options', () => {
'global',
'local',
'pure',
{ compileType: 'module' },
{ compileType: 'icss' },
{ mode: 'global' },
{ mode: 'local' },
{ mode: 'pure' },
@@ -54,6 +56,7 @@ describe('validate options', () => {
'globals',
'locals',
'pures',
{ compileType: 'unknown' },
{ mode: true },
{ mode: 'globals' },
{ mode: 'locals' },