{"name":"css-loader","version":"7.1.4","description":"css loader module for webpack","license":"MIT","repository":{"type":"git","url":"git+https://github.com/webpack/css-loader.git"},"author":{"name":"Tobias Koppers @sokra"},"homepage":"https://github.com/webpack/css-loader","bugs":{"url":"https://github.com/webpack/css-loader/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/webpack"},"main":"dist/cjs.js","engines":{"node":">= 18.12.0"},"scripts":{"start":"npm run build -- -w","clean":"del-cli dist","validate:runtime":"es-check es5 \"dist/runtime/**/*.js\"","prebuild":"npm run clean","build":"cross-env NODE_ENV=production babel src -d dist --copy-files","postbuild":"npm run validate:runtime","commitlint":"commitlint --from=main","security":"npm audit --production","lint:prettier":"prettier --cache --list-different .","lint:js":"eslint --cache .","lint:spelling":"cspell --cache --no-must-find-files --quiet \"**/*.*\"","lint":"npm-run-all -l -p \"lint:**\"","fix:js":"npm run lint:js -- --fix","fix:prettier":"npm run lint:prettier -- --write","fix":"npm-run-all -l fix:js fix:prettier","test:only":"cross-env NODE_ENV=test jest","test:watch":"npm run test:only -- --watch","test:coverage":"npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage","pretest":"npm run lint","test":"npm run test:coverage","prepare":"husky && npm run build","release":"standard-version"},"peerDependencies":{"@rspack/core":"0.x || ^1.0.0 || ^2.0.0-0","webpack":"^5.27.0"},"peerDependenciesMeta":{"@rspack/core":{"optional":true},"webpack":{"optional":true}},"dependencies":{"icss-utils":"^5.1.0","postcss":"^8.4.40","postcss-modules-extract-imports":"^3.1.0","postcss-modules-local-by-default":"^4.0.5","postcss-modules-scope":"^3.2.0","postcss-modules-values":"^4.0.0","postcss-value-parser":"^4.2.0","semver":"^7.6.3"},"devDependencies":{"@babel/cli":"^7.24.8","@babel/core":"^7.25.2","@babel/preset-env":"^7.25.3","@commitlint/cli":"^19.3.0","@commitlint/config-conventional":"^19.2.2","@webpack-contrib/eslint-config-webpack":"^3.0.0","babel-jest":"^30.0.0","cross-env":"^7.0.3","cspell":"^8.13.1","del-cli":"^5.1.0","es-check":"^7.2.1","eslint":"^8.54.0","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.29.0","file-loader":"^6.2.0","husky":"^9.1.4","jest":"^30.0.0","jest-environment-jsdom":"^30.0.0","less":"^4.2.0","less-loader":"^12.2.0","lint-staged":"^15.2.8","memfs":"^4.11.1","mini-css-extract-plugin":"^2.9.0","npm-run-all":"^4.1.5","postcss-loader":"^8.1.1","postcss-preset-env":"^9.6.0","prettier":"^3.3.3","sass":"^1.77.8","sass-loader":"^14.2.1","standard-version":"^9.5.0","strip-ansi":"^6.0.0","style-loader":"^3.3.4","stylus":"^0.63.0","stylus-loader":"^8.1.0","url-loader":"^4.1.1","webpack":"^5.93.0"},"keywords":["webpack","css","loader","url","import"],"gitHead":"5b795afc2fb928e548a06040b1964304f101a2fc","_id":"css-loader@7.1.4","_nodeVersion":"24.11.1","_npmVersion":"11.6.2","dist":{"integrity":"sha512-vv3J9tlOl04WjiMvHQI/9tmIrCxVrj6PFbHemBB1iihpeRbi/I4h033eoFIhwxBBqLhI0KYFS7yvynBFhIZfTw==","shasum":"8f6bf9f8fc8cbef7d2ef6e80acc6545eaefa90b1","tarball":"http://registry-npm.ywwl.com/css-loader/download/css-loader-7.1.4.tgz","fileCount":15,"unpackedSize":142112,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDWBYISaOp6TY3vSPcsjWgeyK5VtwpBEiLHhK/iJ9SYUQIhAJZF672IbsEi/V8a3Lrey4j/tCP67929Bo6aeOKSXCjA"}],"size":32804,"noattachment":false,"key":"/css-loader/-/css-loader-7.1.4.tgz"},"_npmUser":{"name":"evilebottnawi","email":"sheo13666q@gmail.com"},"directories":{},"maintainers":[{"name":"evilebottnawi","email":"sheo13666q@gmail.com"},{"name":"sokra","email":"tobias.koppers@googlemail.com"},{"name":"jhnns","email":"mail@johannesewald.de"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/css-loader_7.1.4_1771248477577_0.736491728204999"},"_hasShrinkwrap":false,"readme":"<div align=\"center\">\n  <img width=\"180\" height=\"180\" vspace=\"20\"\n    src=\"https://cdn.worldvectorlogo.com/logos/css-3.svg\">\n  <a href=\"https://github.com/webpack/webpack\">\n    <img width=\"200\" height=\"200\"\n      src=\"https://webpack.js.org/assets/icon-square-big.svg\">\n  </a>\n</div>\n\n[![npm][npm]][npm-url]\n[![node][node]][node-url]\n[![tests][tests]][tests-url]\n[![coverage][cover]][cover-url]\n[![discussion][discussion]][discussion-url]\n[![size][size]][size-url]\n\n# css-loader\n\nThe `css-loader` interprets `@import` and `url()` like `import/require()` and resolves them.\n\n## Getting Started\n\n> [!WARNING]\n>\n> To use the latest version of css-loader, webpack@5 is required\n\nTo begin, you'll need to install `css-loader`:\n\n```console\nnpm install --save-dev css-loader\n```\n\nor\n\n```console\nyarn add -D css-loader\n```\n\nor\n\n```console\npnpm add -D css-loader\n```\n\nThen, add the loader to your `webpack` configuration. For example:\n\n**file.js**\n\n```js\nimport * as css from \"file.css\";\n```\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        use: [\"style-loader\", \"css-loader\"],\n      },\n    ],\n  },\n};\n```\n\nFinally, run `webpack` using the method you normally use (e.g., via CLI or an npm script).\n\nIf you need to extract CSS into a separate file (i.e. do not store CSS in a JS module), consider using the [recommend example](https://github.com/webpack/css-loader#recommend).\n\n## Options\n\n- **[`url`](#url)**\n- **[`import`](#import)**\n- **[`modules`](#modules)**\n- **[`sourceMap`](#sourcemap)**\n- **[`importLoaders`](#importloaders)**\n- **[`esModule`](#esmodule)**\n- **[`exportType`](#exporttype)**\n\n### `url`\n\nType:\n\n```ts\ntype url =\n  | boolean\n  | {\n      filter: (url: string, resourcePath: string) => boolean;\n    };\n```\n\nDefault: `true`\n\nEnables or disables handling the CSS functions `url` and `image-set`.\n\n- If set to `false`, `css-loader` will not parse any paths specified in `url` or `image-set`.\n- You can also pass a function to control this behavior dynamically based on the asset path.\n\nAs of version [4.0.0](https://github.com/webpack/css-loader/main/CHANGELOG.md#400-2020-07-25), absolute paths are resolved based on the server root.\n\nExamples resolutions:\n\n```js\nurl(image.png) => require('./image.png')\nurl('image.png') => require('./image.png')\nurl(./image.png) => require('./image.png')\nurl('./image.png') => require('./image.png')\nurl('http://dontwritehorriblecode.com/2112.png') => require('http://dontwritehorriblecode.com/2112.png')\nimage-set(url('image2x.png') 1x, url('image1x.png') 2x) => require('./image1x.png') and require('./image2x.png')\n```\n\nTo import assets from a `node_modules` path (including `resolve.modules`) or an `alias`, prefix it with a `~`:\n\n```js\nurl(~module/image.png) => require('module/image.png')\nurl('~module/image.png') => require('module/image.png')\nurl(~aliasDirectory/image.png) => require('otherDirectory/image.png')\n```\n\n#### `boolean`\n\nEnable/disable `url()` resolving.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          url: true,\n        },\n      },\n    ],\n  },\n};\n```\n\n#### `object`\n\nAllows filtering of `url()` values.\n\nAny filtered `url()` will not be resolved (left in the code as they were written).\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          url: {\n            filter: (url, resourcePath) => {\n              // resourcePath - path to css file\n\n              // Don't handle `img.png` urls\n              if (url.includes(\"img.png\")) {\n                return false;\n              }\n\n              // Don't handle images under root-relative /external_images/\n              if (/^\\/external_images\\//.test(url)) {\n                return false;\n              }\n\n              return true;\n            },\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n### `import`\n\nType:\n\n<!-- use other name to prettify since import is reserved keyword -->\n\n```ts\ntype importFn =\n  | boolean\n  | {\n      filter: (\n        url: string,\n        media: string,\n        resourcePath: string,\n        supports?: string,\n        layer?: string,\n      ) => boolean;\n    };\n```\n\nDefault: `true`\n\nAllows you to enable or disable handling of `@import` at-rules.\n\nControls how `@import` statements are resolved.\n\nAbsolute URLs in `@import` will be moved in runtime code.\n\nExamples resolutions:\n\n```\n@import 'style.css' => require('./style.css')\n@import url(style.css) => require('./style.css')\n@import url('style.css') => require('./style.css')\n@import './style.css' => require('./style.css')\n@import url(./style.css) => require('./style.css')\n@import url('./style.css') => require('./style.css')\n@import url('http://dontwritehorriblecode.com/style.css') => @import url('http://dontwritehorriblecode.com/style.css') in runtime\n```\n\nTo import styles from a `node_modules` path (include `resolve.modules`) or an `alias`, prefix it with a `~`:\n\n```\n@import url(~module/style.css) => require('module/style.css')\n@import url('~module/style.css') => require('module/style.css')\n@import url(~aliasDirectory/style.css) => require('otherDirectory/style.css')\n```\n\n#### `boolean`\n\nEnable/disable `@import` resolving.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          import: true,\n        },\n      },\n    ],\n  },\n};\n```\n\n#### `object`\n\n##### `filter`\n\nType:\n\n```ts\ntype filter = (url: string, media: string, resourcePath: string) => boolean;\n```\n\nDefault: `undefined`\n\nAllows filtering of `@import`.\n\nAny filtered `@import` will not be resolved (left in the code as they were written).\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          import: {\n            filter: (url, media, resourcePath) => {\n              // resourcePath - path to css file\n\n              // Don't handle `style.css` import\n              if (url.includes(\"style.css\")) {\n                return false;\n              }\n\n              return true;\n            },\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n### `modules`\n\nType:\n\n```ts\ntype modules =\n  | boolean\n  | \"local\"\n  | \"global\"\n  | \"pure\"\n  | \"icss\"\n  | {\n      auto: boolean | regExp | ((resourcePath: string) => boolean);\n      mode:\n        | \"local\"\n        | \"global\"\n        | \"pure\"\n        | \"icss\"\n        | ((resourcePath) => \"local\" | \"global\" | \"pure\" | \"icss\");\n      localIdentName: string;\n      localIdentContext: string;\n      localIdentHashSalt: string;\n      localIdentHashFunction: string;\n      localIdentHashDigest: string;\n      localIdentRegExp: string | regExp;\n      getLocalIdent: (\n        context: LoaderContext,\n        localIdentName: string,\n        localName: string,\n      ) => string;\n      namedExport: boolean;\n      exportGlobals: boolean;\n      exportLocalsConvention:\n        | \"as-is\"\n        | \"camel-case\"\n        | \"camel-case-only\"\n        | \"dashes\"\n        | \"dashes-only\"\n        | ((name: string) => string);\n      exportOnlyLocals: boolean;\n      getJSON: ({\n        resourcePath,\n        imports,\n        exports,\n        replacements,\n      }: {\n        resourcePath: string;\n        imports: object[];\n        exports: object[];\n        replacements: object[];\n      }) => Promise<void> | void;\n    };\n```\n\nDefault: `undefined`\n\nAllows you to enable or disable CSS Modules or ICSS and configure them:\n\n- `undefined`: Enables CSS modules for all files matching `/\\.module\\.\\w+$/i.test(filename)` or `/\\.icss\\.\\w+$/i.test(filename)` regexp.\n- `true`: Enables CSS modules for all files.\n- `false`: Disables CSS Modules for all files.\n- `string`: Disables CSS Modules for all files and set the `mode` option (see [mode](https://github.com/webpack/css-loader#mode) for details).\n- `object`: Enables CSS modules for all files unless the `modules.auto` option is provided. otherwise the `modules.auto` option will determine whether if it is CSS Modules or not (see [auto](https://github.com/webpack/css-loader#auto) for more details).\n\nThe `modules` option enables/disables the **[CSS Modules](https://github.com/css-modules/css-modules)** specification and configures its behavior.\n\nSetting `modules: false` can improve performance because we avoid parsing **CSS Modules** features, this is useful for developers using use vanilla CSS or other technologies.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: true,\n        },\n      },\n    ],\n  },\n};\n```\n\n#### `Features`\n\n##### `Scope`\n\n- Using `local` value requires you to specify `:global` classes.\n- Using `global` value requires you to specify `:local` classes.\n- Using `pure` value requires selectors must contain at least one local class or ID.\n\nYou can find more information on scoping module [here](https://github.com/css-modules/css-modules).\n\nWith CSS Modules, styles are scoped locally, preventing conflicts with global styles.\n\nUse `:local(.className)` to declare a `className` in the local scope. The local identifiers are exported by the module.\n\n- With `:local` (without parentheses) local mode can be switched `on` for this selector.\n- The `:global(.className)` notation can be used to declare an explicit global selector.\n- With `:global` (without parentheses) global mode can be switched `on` for this selector.\n\nThe loader replaces local selectors with unique, scoped identifiers. The chosen unique identifiers are exported by the module.\n\n```css\n:local(.className) {\n  background: red;\n}\n:local .className {\n  color: green;\n}\n:local(.className .subClass) {\n  color: green;\n}\n:local .className .subClass :global(.global-class-name) {\n  color: blue;\n}\n```\n\nOutput (example):\n\n```css\n._23_aKvs-b8bW2Vg3fwHozO {\n  background: red;\n}\n._23_aKvs-b8bW2Vg3fwHozO {\n  color: green;\n}\n._23_aKvs-b8bW2Vg3fwHozO ._13LGdX8RMStbBE9w-t0gZ1 {\n  color: green;\n}\n._23_aKvs-b8bW2Vg3fwHozO ._13LGdX8RMStbBE9w-t0gZ1 .global-class-name {\n  color: blue;\n}\n```\n\n> [!NOTE]\n>\n> Identifiers are exported\n\n```js\nexports.locals = {\n  className: \"_23_aKvs-b8bW2Vg3fwHozO\",\n  subClass: \"_13LGdX8RMStbBE9w-t0gZ1\",\n};\n```\n\nCamelCase naming is recommended for local selectors, as it simplifies usage in imported JS modules.\n\nAlthough you can use `:local(#someId)`, but this is not recommended. Prefer classes instead of IDs for modular styling.\n\n##### `Composing`\n\nWhen declaring a local class name, you can compose it from one or more other local class names.\n\n```css\n:local(.className) {\n  background: red;\n  color: yellow;\n}\n\n:local(.subClass) {\n  composes: className;\n  background: blue;\n}\n```\n\nThis does not alter the final CSS output, but the generated `subClass` will include both class names in its export.\n\n```js\nexports.locals = {\n  className: \"_23_aKvs-b8bW2Vg3fwHozO\",\n  subClass: \"_13LGdX8RMStbBE9w-t0gZ1 _23_aKvs-b8bW2Vg3fwHozO\",\n};\n```\n\n```css\n._23_aKvs-b8bW2Vg3fwHozO {\n  background: red;\n  color: yellow;\n}\n\n._13LGdX8RMStbBE9w-t0gZ1 {\n  background: blue;\n}\n```\n\n##### `Importing`\n\nTo import a local class names from another module.\n\n> [!NOTE]\n>\n> It is highly recommended to include file extensions when importing a file, since it is possible to import a file with any extension and it is not known in advance which file to use.\n\n```css\n:local(.continueButton) {\n  composes: button from \"library/button.css\";\n  background: red;\n}\n```\n\n```css\n:local(.nameEdit) {\n  composes: edit highlight from \"./edit.css\";\n  background: red;\n}\n```\n\nTo import from multiple modules use multiple `composes:` rules.\n\n```css\n:local(.className) {\n  composes:\n    edit highlight from \"./edit.css\",\n    button from \"module/button.css\",\n    classFromThisModule;\n  background: red;\n}\n```\n\nor\n\n```css\n:local(.className) {\n  composes: edit highlight from \"./edit.css\";\n  composes: button from \"module/button.css\";\n  composes: classFromThisModule;\n  background: red;\n}\n```\n\n##### `Values`\n\nYou can use `@value` to specific values to be reused throughout a document.\n\nWe recommend following a naming convention:\n\n- `v-` prefix for values\n- `s-` prefix for selectors\n- `m-` prefix for media at-rules.\n\n```css\n@value v-primary: #BF4040;\n@value s-black: black-selector;\n@value m-large: (min-width: 960px);\n\n.header {\n  color: v-primary;\n  padding: 0 10px;\n}\n\n.s-black {\n  color: black;\n}\n\n@media m-large {\n  .header {\n    padding: 0 20px;\n  }\n}\n```\n\n#### `boolean`\n\nEnable **CSS Modules** features.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: true,\n        },\n      },\n    ],\n  },\n};\n```\n\n#### `string`\n\nEnable **CSS Modules** features and setup `mode`.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          // Using `local` value has same effect like using `modules: true`\n          modules: \"global\",\n        },\n      },\n    ],\n  },\n};\n```\n\n#### `object`\n\nEnable **CSS Modules** features and configure its behavior through `options`.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            mode: \"local\",\n            auto: true,\n            exportGlobals: true,\n            localIdentName: \"[path][name]__[local]--[hash:base64:5]\",\n            localIdentContext: path.resolve(__dirname, \"src\"),\n            localIdentHashSalt: \"my-custom-hash\",\n            namedExport: true,\n            exportLocalsConvention: \"as-is\",\n            exportOnlyLocals: false,\n            getJSON: ({ resourcePath, imports, exports, replacements }) => {},\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `auto`\n\nType:\n\n```ts\ntype auto =\n  | boolean\n  | regExp\n  | ((\n      resourcePath: string,\n      resourceQuery: string,\n      resourceFragment: string,\n    ) => boolean);\n```\n\nDefault: `undefined`\n\nAllows auto enable CSS modules or ICSS based on the file name, query or fragment when `modules` option is an object.\n\nPossible values:\n\n- `undefined`: Enables CSS modules for all files.\n- `true`: Enables CSS modules for files matching `/\\.module\\.\\w+$/i.test(filename)` and `/\\.icss\\.\\w+$/i.test(filename)` regexp.\n- `false`: Disables CSS Modules for all files.\n- `RegExp`: Enables CSS modules for all files matching `/RegExp/i.test(filename)` regexp.\n- `function`: Enables CSS Modules for files based on the file name satisfying your filter function check.\n\n###### `boolean`\n\nPossible values:\n\n- `true`: Enables CSS modules or Interoperable CSS (ICSS) 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.\n- `false`: Disables CSS modules or ICSS format based on filename for all files.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            auto: true,\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n###### `RegExp`\n\nEnables CSS modules for files based on the filename satisfying your regex check.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            auto: /\\.custom-module\\.\\w+$/i,\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n###### `function`\n\nEnables CSS Modules for files based on the filename, query or fragment satisfying your filter function check.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            auto: (resourcePath, resourceQuery, resourceFragment) => {\n              return resourcePath.endsWith(\".custom-module.css\");\n            },\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `mode`\n\nType:\n\n```ts\ntype mode =\n  | \"local\"\n  | \"global\"\n  | \"pure\"\n  | \"icss\"\n  | ((\n      resourcePath: string,\n      resourceQuery: string,\n      resourceFragment: string,\n    ) => \"local\" | \"global\" | \"pure\" | \"icss\");\n```\n\nDefault: `'local'`\n\nSetup `mode` option. You can omit the value when you want `local` mode.\n\nControls the level of compilation applied to the input styles.\n\n- The `local`, `global`, and `pure` handles `class` and `id` scoping and `@value` values.\n- The `icss` will only compile the low level `Interoperable CSS (ICSS)` format for declaring `:import` and `:export` dependencies between CSS and other languages.\n\nICSS underpins CSS Module support, and provides a low level syntax for other tools to implement CSS-module variations of their own.\n\n###### `string`\n\nPossible values - `local`, `global`, `pure`, and `icss`.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            mode: \"global\",\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n###### `function`\n\nAllows setting different values for the `mode` option based on the filename, query or fragment.\nPossible return values - `local`, `global`, `pure` and `icss`.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            // Callback must return \"local\", \"global\", or \"pure\" values\n            mode: (resourcePath, resourceQuery, resourceFragment) => {\n              if (/pure.css$/i.test(resourcePath)) {\n                return \"pure\";\n              }\n\n              if (/global.css$/i.test(resourcePath)) {\n                return \"global\";\n              }\n\n              return \"local\";\n            },\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `localIdentName`\n\nType:\n\n```ts\ntype localIdentName = string;\n```\n\nDefault: `'[hash:base64]'`\n\nAllows to configure the generated local ident name.\n\nFor more information on options see:\n\n- [webpack template strings](https://webpack.js.org/configuration/output/#template-strings),\n- [output.hashDigest](https://webpack.js.org/configuration/output/#outputhashdigest),\n- [output.hashDigestLength](https://webpack.js.org/configuration/output/#outputhashdigestlength),\n- [output.hashFunction](https://webpack.js.org/configuration/output/#outputhashfunction),\n- [output.hashSalt](https://webpack.js.org/configuration/output/#outputhashsalt).\n\nSupported template strings:\n\n- `[name]` the basename of the resource\n- `[folder]` the folder the resource relative to the `compiler.context` option or `modules.localIdentContext` option.\n- `[path]` the path of the resource relative to the `compiler.context` option or `modules.localIdentContext` option.\n- `[file]` - filename and path.\n- `[ext]` - extension with leading `.`.\n- `[hash]` - the hash of the string, generated based on `localIdentHashSalt`, `localIdentHashFunction`, `localIdentHashDigest`, `localIdentHashDigestLength`, `localIdentContext`, `resourcePath` and `exportName`\n- `[<hashFunction>:hash:<hashDigest>:<hashDigestLength>]` - hash with hash settings.\n- `[local]` - original class.\n\nRecommendations:\n\n- Use `'[path][name]__[local]'` for development\n- Use `'[hash:base64]'` for production\n\nThe `[local]` placeholder contains original class.\n\n**Note:** all reserved characters (`<>:\"/\\|?*`) and control filesystem characters (excluding characters in the `[local]` placeholder) will be converted to `-`.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            localIdentName: \"[path][name]__[local]--[hash:base64:5]\",\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `localIdentContext`\n\nType:\n\n```ts\ntype localIdentContex = string;\n```\n\nDefault: `compiler.context`\n\nAllows redefining the basic loader context for local ident name.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            localIdentContext: path.resolve(__dirname, \"src\"),\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `localIdentHashSalt`\n\nType:\n\n```ts\ntype localIdentHashSalt = string;\n```\n\nDefault: `undefined`\n\nAllows to add custom hash to generate more unique classes.\n\nFor more information see [output.hashSalt](https://webpack.js.org/configuration/output/#outputhashsalt).\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            localIdentHashSalt: \"hash\",\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `localIdentHashFunction`\n\nType:\n\n```ts\ntype localIdentHashFunction = string;\n```\n\nDefault: `md4`\n\nAllows to specify hash function to generate classes .\n\nFor more information see [output.hashFunction](https://webpack.js.org/configuration/output/#outputhashfunction).\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            localIdentHashFunction: \"md4\",\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `localIdentHashDigest`\n\nType:\n\n```ts\ntype localIdentHashDigest = string;\n```\n\nDefault: `hex`\n\nAllows to specify hash digest to generate classes.\n\nFor more information see [output.hashDigest](https://webpack.js.org/configuration/output/#outputhashdigest).\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            localIdentHashDigest: \"base64\",\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `localIdentHashDigestLength`\n\nType:\n\n```ts\ntype localIdentHashDigestLength = number;\n```\n\nDefault: `20`\n\nAllows to specify hash digest length to generate classes.\n\nFor more information, see [output.hashDigestLength](https://webpack.js.org/configuration/output/#outputhashdigestlength).\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            localIdentHashDigestLength: 5,\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `hashStrategy`\n\nType: `'resource-path-and-local-name' | 'minimal-subset'`\nDefault: `'resource-path-and-local-name'`\n\nShould local name be used when computing the hash.\n\n- `'resource-path-and-local-name'` Both resource path and local name are used when hashing. Each identifier in a module gets its own hash digest, always.\n- `'minimal-subset'` Auto detect if identifier names can be omitted from hashing. Use this value to optimize the output for better GZIP or Brotli compression.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            hashStrategy: \"minimal-subset\",\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `localIdentRegExp`\n\nType:\n\n```ts\ntype localIdentRegExp = string | RegExp;\n```\n\nDefault: `undefined`\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            localIdentRegExp: /page-(.*)\\.css/i,\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `getLocalIdent`\n\nType:\n\n```ts\ntype getLocalIdent = (\n  context: LoaderContext,\n  localIdentName: string,\n  localName: string,\n) => string;\n```\n\nDefault: `undefined`\n\nAllows to specify a function to generate the classname.\n\nBy default we use built-in function to generate a classname.\n\nIf your custom function returns `null` or `undefined`, the built-in generator is used as a `fallback`.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            getLocalIdent: (context, localIdentName, localName, options) => {\n              return \"whatever_random_class_name\";\n            },\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `namedExport`\n\nType:\n\n```ts\ntype namedExport = boolean;\n```\n\nDefault: Depends on the value of the `esModule` option. If the value of the `esModule` options is `true`, `namedExport` defaults to `true` ; otherwise, it defaults to `false`.\n\nEnables or disables ES modules named export for locals.\n\n> [!WARNING]\n>\n> The `default` class name cannot be used directly when `namedExport` is `true` because `default` is a reserved keyword in ECMAScript modules. It is automatically renamed to `_default`.\n\n**styles.css**\n\n```css\n.foo-baz {\n  color: red;\n}\n.bar {\n  color: blue;\n}\n.default {\n  color: green;\n}\n```\n\n**index.js**\n\n```js\nimport * as styles from \"./styles.css\";\n\n// If using `exportLocalsConvention: \"as-is\"` (default value):\nconsole.log(styles[\"foo-baz\"], styles.bar);\n\n// If using `exportLocalsConvention: \"camel-case-only\"`:\nconsole.log(styles.fooBaz, styles.bar);\n\n// For the `default` classname\nconsole.log(styles[\"_default\"]);\n```\n\nYou can enable ES module named export using:\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          esModule: true,\n          modules: {\n            namedExport: true,\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\nTo set a custom name for namedExport, can use [`exportLocalsConvention`](#exportLocalsConvention) option as a function.\n\nSee below in the [`examples`](#examples) section.\n\n##### `exportGlobals`\n\nType:\n\n```ts\ntype exportsGLobals = boolean;\n```\n\nDefault: `false`\n\nAllow `css-loader` to export names from global class or ID, so you can use that as local name.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            exportGlobals: true,\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `exportLocalsConvention`\n\nType:\n\n```ts\ntype exportLocalsConvention =\n  | \"as-is\"\n  | \"camel-case\"\n  | \"camel-case-only\"\n  | \"dashes\"\n  | \"dashes-only\"\n  | ((name: string) => string);\n```\n\nDefault: Depends on the value of the `modules.namedExport` option:\n\n- If `true` - `as-is`\n- Otherwise `camel-case-only` (class names converted to camelCase, original name removed).\n\n> [!WARNING]\n>\n> Names of locals are converted to camelCase when the named export is `false`, i.e. the `exportLocalsConvention` option has`camelCaseOnly` value by default.\n> You can set this back to any other valid option but selectors which are not valid JavaScript identifiers may run into problems which do not implement the entire modules specification.\n\nStyle of exported class names.\n\n###### `string`\n\nBy default, the exported JSON keys mirror the class names (i.e `as-is` value).\n\n|          Name           |   Type   | Description                                                                                         |\n| :---------------------: | :------: | :-------------------------------------------------------------------------------------------------- |\n|      **`'as-is'`**      | `string` | Class names will be exported as is.                                                                 |\n|   **`'camel-case'`**    | `string` | Class names will be camelCased, but the original class name will not to be removed from the locals. |\n| **`'camel-case-only'`** | `string` | Class names will be camelCased, and original class name will be removed from the locals.            |\n|     **`'dashes'`**      | `string` | Only dashes in class names will be camelCased                                                       |\n|   **`'dashes-only'`**   | `string` | Dashes in class names will be camelCased, the original class name will be removed from the locals   |\n\n**file.css**\n\n```css\n.class-name {\n}\n```\n\n**file.js**\n\n```js\nimport { className } from \"file.css\";\n```\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            exportLocalsConvention: \"camel-case-only\",\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n###### `function`\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            exportLocalsConvention: function (name) {\n              return name.replace(/-/g, \"_\");\n            },\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            exportLocalsConvention: function (name) {\n              return [\n                name.replace(/-/g, \"_\"),\n                // dashesCamelCase\n                name.replace(/-+(\\w)/g, (match, firstLetter) =>\n                  firstLetter.toUpperCase(),\n                ),\n              ];\n            },\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `exportOnlyLocals`\n\nType:\n\n```ts\ntype exportOnlyLocals = boolean;\n```\n\nDefault: `false`\n\nExport only locals.\n\n**Useful** when you use **css modules** for pre-rendering (for example SSR).\n\nFor pre-rendering with `mini-css-extract-plugin` you should use this option instead of `style-loader!css-loader` **in the pre-rendering bundle**.\n\nIt doesn't embed CSS; it only exports the identifier mappings.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            exportOnlyLocals: true,\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n##### `getJSON`\n\nType:\n\n```ts\ntype getJSON = ({\n  resourcePath,\n  imports,\n  exports,\n  replacements,\n}: {\n  resourcePath: string;\n  imports: object[];\n  exports: object[];\n  replacements: object[];\n}) => Promise<void> | void;\n```\n\nDefault: `undefined`\n\nEnables a callback to output the CSS modules mapping JSON.\n\nThe callback is invoked with an object containing the following:\n\n- `resourcePath`: the absolute path of the original resource, e.g., `/foo/bar/baz.module.css`\n\n- `imports`: an array of import objects with data about import types and file paths, e.g.,\n\n```json\n[\n  {\n    \"type\": \"icss_import\",\n    \"importName\": \"___CSS_LOADER_ICSS_IMPORT_0___\",\n    \"url\": \"\\\"-!../../../../../node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[4].use[1]!../../../../../node_modules/postcss-loader/dist/cjs.js!../../../../../node_modules/sass-loader/dist/cjs.js!../../../../baz.module.css\\\"\",\n    \"icss\": true,\n    \"index\": 0\n  }\n]\n```\n\n(Note that this will include all imports, not just those relevant to CSS Modules.)\n\n- `exports`: an array of export objects with exported names and values, e.g.,\n\n```json\n[\n  {\n    \"name\": \"main\",\n    \"value\": \"D2Oy\"\n  }\n]\n```\n\n- `replacements`: an array of import replacement objects used for linking `imports` and `exports`, e.g.,\n\n```json\n{\n  \"replacementName\": \"___CSS_LOADER_ICSS_IMPORT_0_REPLACEMENT_0___\",\n  \"importName\": \"___CSS_LOADER_ICSS_IMPORT_0___\",\n  \"localName\": \"main\"\n}\n```\n\nUsing `getJSON`, it's possible to output a file with all CSS module mappings.\n\nIn the following example, we use `getJSON` to cache canonical mappings and add stand-ins for any composed values (through `composes`), and we use a custom plugin to consolidate the values and output them to a file:\n\n**webpack.config.js**\n\n```js\nconst path = require(\"path\");\nconst fs = require(\"fs\");\n\nconst CSS_LOADER_REPLACEMENT_REGEX =\n  /(___CSS_LOADER_ICSS_IMPORT_\\d+_REPLACEMENT_\\d+___)/g;\nconst REPLACEMENT_REGEX = /___REPLACEMENT\\[(.*?)]\\[(.*?)]___/g;\nconst IDENTIFIER_REGEX = /\\[(.*?)]\\[(.*?)]/;\nconst replacementsMap = {};\nconst canonicalValuesMap = {};\nconst allExportsJson = {};\n\nfunction generateIdentifier(resourcePath, localName) {\n  return `[${resourcePath}][${localName}]`;\n}\n\nfunction addReplacements(resourcePath, imports, exportsJson, replacements) {\n  const importReplacementsMap = {};\n\n  // create a dict to quickly identify imports and get their absolute stand-in strings in the currently loaded file\n  // e.g., { '___CSS_LOADER_ICSS_IMPORT_0_REPLACEMENT_0___': '___REPLACEMENT[/foo/bar/baz.css][main]___' }\n  importReplacementsMap[resourcePath] = replacements.reduce(\n    (acc, { replacementName, importName, localName }) => {\n      const replacementImportUrl = imports.find(\n        (importData) => importData.importName === importName,\n      ).url;\n      const relativePathRe = /.*!(.*)\"/;\n      const [, relativePath] = replacementImportUrl.match(relativePathRe);\n      const importPath = path.resolve(path.dirname(resourcePath), relativePath);\n      const identifier = generateIdentifier(importPath, localName);\n      return { ...acc, [replacementName]: `___REPLACEMENT${identifier}___` };\n    },\n    {},\n  );\n\n  // iterate through the raw exports and add stand-in variables\n  // ('___REPLACEMENT[<absolute_path>][<class_name>]___')\n  // to be replaced in the plugin below\n  for (const [localName, classNames] of Object.entries(exportsJson)) {\n    const identifier = generateIdentifier(resourcePath, localName);\n\n    if (CSS_LOADER_REPLACEMENT_REGEX.test(classNames)) {\n      // if there are any replacements needed in the concatenated class names,\n      // add them all to the replacements map to be replaced altogether later\n      replacementsMap[identifier] = classNames.replaceAll(\n        CSS_LOADER_REPLACEMENT_REGEX,\n        (_, replacementName) =>\n          importReplacementsMap[resourcePath][replacementName],\n      );\n    } else {\n      // otherwise, no class names need replacements so we can add them to\n      // canonical values map and all exports JSON verbatim\n      canonicalValuesMap[identifier] = classNames;\n\n      allExportsJson[resourcePath] = allExportsJson[resourcePath] || {};\n      allExportsJson[resourcePath][localName] = classNames;\n    }\n  }\n}\n\nfunction replaceReplacements(classNames) {\n  return classNames.replaceAll(\n    REPLACEMENT_REGEX,\n    (_, resourcePath, localName) => {\n      const identifier = generateIdentifier(resourcePath, localName);\n\n      if (identifier in canonicalValuesMap) {\n        return canonicalValuesMap[identifier];\n      }\n\n      // Recurse through other stand-in that may be imports\n      const canonicalValue = replaceReplacements(replacementsMap[identifier]);\n\n      canonicalValuesMap[identifier] = canonicalValue;\n\n      return canonicalValue;\n    },\n  );\n}\n\nfunction getJSON({ resourcePath, imports, exports, replacements }) {\n  const exportsJson = exports.reduce((acc, { name, value }) => {\n    return { ...acc, [name]: value };\n  }, {});\n\n  if (replacements.length > 0) {\n    // replacements present --> add stand-in values for absolute paths and local names,\n    // which will be resolved to their canonical values in the plugin below\n    addReplacements(resourcePath, imports, exportsJson, replacements);\n  } else {\n    // no replacements present --> add to canonicalValuesMap verbatim\n    // since all values here are canonical/don't need resolution\n    for (const [key, value] of Object.entries(exportsJson)) {\n      const id = `[${resourcePath}][${key}]`;\n\n      canonicalValuesMap[id] = value;\n    }\n\n    allExportsJson[resourcePath] = exportsJson;\n  }\n}\n\nclass CssModulesJsonPlugin {\n  constructor(options) {\n    this.options = options;\n  }\n\n  // eslint-disable-next-line class-methods-use-this\n  apply(compiler) {\n    compiler.hooks.emit.tap(\"CssModulesJsonPlugin\", () => {\n      for (const [identifier, classNames] of Object.entries(replacementsMap)) {\n        const adjustedClassNames = replaceReplacements(classNames);\n\n        replacementsMap[identifier] = adjustedClassNames;\n\n        const [, resourcePath, localName] = identifier.match(IDENTIFIER_REGEX);\n\n        allExportsJson[resourcePath] = allExportsJson[resourcePath] || {};\n        allExportsJson[resourcePath][localName] = adjustedClassNames;\n      }\n\n      fs.writeFileSync(\n        this.options.filepath,\n        JSON.stringify(\n          // Make path to be relative to `context` (your project root)\n          Object.fromEntries(\n            Object.entries(allExportsJson).map((key) => {\n              key[0] = path\n                .relative(compiler.context, key[0])\n                .replace(/\\\\/g, \"/\");\n\n              return key;\n            }),\n          ),\n          null,\n          2,\n        ),\n        \"utf8\",\n      );\n    });\n  }\n}\n\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: { modules: { getJSON } },\n      },\n    ],\n  },\n  plugins: [\n    new CssModulesJsonPlugin({\n      filepath: path.resolve(__dirname, \"./output.css.json\"),\n    }),\n  ],\n};\n```\n\nIn the above, all import aliases are replaced with `___REPLACEMENT[<resourcePath>][<localName>]___` in `getJSON`, and they're resolved in the custom plugin. All CSS mappings are contained in `allExportsJson`:\n\n```json\n{\n  \"foo/bar/baz.module.css\": {\n    \"main\": \"D2Oy\",\n    \"header\": \"thNN\"\n  },\n  \"foot/bear/bath.module.css\": {\n    \"logo\": \"sqiR\",\n    \"info\": \"XMyI\"\n  }\n}\n```\n\nThis is saved to a local file named `output.css.json`.\n\n### `importLoaders`\n\nType:\n\n```ts\ntype importLoaders = number;\n```\n\nDefault: `0`\n\nAllows to enables/disables or sets up the number of loaders applied before CSS loader for `@import` at-rules, CSS Modules and ICSS imports, i.e. `@import`/`composes`/`@value value from './values.css'`/etc.\n\nThe option `importLoaders` allows you to configure how many loaders before `css-loader` should be applied to `@import`ed resources and CSS Modules/ICSS imports.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        use: [\n          \"style-loader\",\n          {\n            loader: \"css-loader\",\n            options: {\n              importLoaders: 2,\n              // 0 => no loaders (default);\n              // 1 => postcss-loader;\n              // 2 => postcss-loader, sass-loader\n            },\n          },\n          \"postcss-loader\",\n          \"sass-loader\",\n        ],\n      },\n    ],\n  },\n};\n```\n\nThis may change in the future when the module system (i. e. webpack) supports loader matching by origin.\n\n### `sourceMap`\n\nType:\n\n```ts\ntype sourceMap = boolean;\n```\n\nDefault: depends on the `compiler.devtool` value\n\nBy default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option. All values enable source map generation except `eval` and `false` values.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          sourceMap: true,\n        },\n      },\n    ],\n  },\n};\n```\n\n### `esModule`\n\nType:\n\n```ts\ntype esModule = boolean;\n```\n\nDefault: `true`\n\nBy default, `css-loader` generates JS modules that use the ES modules syntax.\n\nThere are some cases in which using ES modules is beneficial, like in the case of [module concatenation](https://webpack.js.org/plugins/module-concatenation-plugin/) and [tree shaking](https://webpack.js.org/guides/tree-shaking/).\n\nYou can enable CommonJS module syntax using:\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          esModule: false,\n        },\n      },\n    ],\n  },\n};\n```\n\n### `exportType`\n\nType:\n\n```ts\ntype exportType = \"array\" | \"string\" | \"css-style-sheet\";\n```\n\nDefault: `'array'`\n\nAllows exporting styles as array with modules, string or [constructable stylesheet](https://developers.google.com/web/updates/2019/02/constructable-stylesheets) (i.e. [`CSSStyleSheet`](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet)).\n\nThe default value is `'array'`, i.e. loader exports an array of modules with a specific API which is used in `style-loader` or other.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        assert: { type: \"css\" },\n        loader: \"css-loader\",\n        options: {\n          exportType: \"css-style-sheet\",\n        },\n      },\n    ],\n  },\n};\n```\n\n**src/index.js**\n\n```js\nimport sheet from \"./styles.css\" assert { type: \"css\" };\n\ndocument.adoptedStyleSheets = [sheet];\nshadowRoot.adoptedStyleSheets = [sheet];\n```\n\n#### `'array'`\n\nThe default export is array of modules with specific API which is used in `style-loader` or other.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.(sa|sc|c)ss$/i,\n        use: [\"style-loader\", \"css-loader\", \"postcss-loader\", \"sass-loader\"],\n      },\n    ],\n  },\n};\n```\n\n**src/index.js**\n\n```js\n// `style-loader` applies styles to DOM\nimport \"./styles.css\";\n```\n\n#### `'string'`\n\n> [!WARNING]\n>\n> You should not use [`style-loader`](https://github.com/webpack/style-loader) or [`mini-css-extract-plugin`](https://github.com/webpack/mini-css-extract-plugin) with this value.\n>\n> The `esModule` option should be enabled if you want to use it with [`CSS modules`](https://github.com/webpack/css-loader#modules). By default for locals [named export](https://github.com/webpack/css-loader#namedexport) will be used.\n\nThe default export is `string`.\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.(sa|sc|c)ss$/i,\n        use: [\"css-loader\", \"postcss-loader\", \"sass-loader\"],\n      },\n    ],\n  },\n};\n```\n\n**src/index.js**\n\n```js\nimport sheet from \"./styles.css\";\n\nconsole.log(sheet);\n```\n\n#### `'css-style-sheet'`\n\n> [!WARNING]\n>\n> `@import` rules not yet allowed, more [information](https://web.dev/css-module-scripts/#@import-rules-not-yet-allowed)\n\n> [!WARNING]\n>\n> You don't need [`style-loader`](https://github.com/webpack/style-loader) anymore, please remove it.\n\n> [!WARNING]\n>\n> The `esModule` option should be enabled if you want to use it with [`CSS modules`](https://github.com/webpack/css-loader#modules). By default for locals [named export](https://github.com/webpack/css-loader#namedexport) will be used.\n\n> [!WARNING]\n>\n> Source maps are not currently supported in `Chrome` due to a [bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1174094&q=CSSStyleSheet%20source%20maps&can=2)\n\nThe default export is a [constructable stylesheet](https://developers.google.com/web/updates/2019/02/constructable-stylesheets) (i.e. [`CSSStyleSheet`](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet)).\n\nUseful for [custom elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) and shadow DOM.\n\nMore information:\n\n- [Using CSS Module Scripts to import stylesheets](https://web.dev/css-module-scripts/)\n- [Constructable Stylesheets: seamless reusable styles](https://developers.google.com/web/updates/2019/02/constructable-stylesheets)\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        assert: { type: \"css\" },\n        loader: \"css-loader\",\n        options: {\n          exportType: \"css-style-sheet\",\n        },\n      },\n\n      // For Sass/SCSS:\n      //\n      // {\n      //   assert: { type: \"css\" },\n      //   rules: [\n      //     {\n      //       loader: \"css-loader\",\n      //       options: {\n      //         exportType: \"css-style-sheet\",\n      //         // Other options\n      //       },\n      //     },\n      //     {\n      //       loader: \"sass-loader\",\n      //       options: {\n      //         // Other options\n      //       },\n      //     },\n      //   ],\n      // },\n    ],\n  },\n};\n```\n\n**src/index.js**\n\n```js\n// Example for Sass/SCSS:\n// import sheet from \"./styles.scss\" assert { type: \"css\" };\n\n// Example for CSS modules:\n// import sheet, { myClass } from \"./styles.scss\" assert { type: \"css\" };\n\n// Example for CSS:\nimport sheet from \"./styles.css\" assert { type: \"css\" };\n\ndocument.adoptedStyleSheets = [sheet];\nshadowRoot.adoptedStyleSheets = [sheet];\n```\n\nFor migration purposes, you can use the following configuration:\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        oneOf: [\n          {\n            assert: { type: \"css\" },\n            loader: \"css-loader\",\n            options: {\n              exportType: \"css-style-sheet\",\n              // Other options\n            },\n          },\n          {\n            use: [\n              \"style-loader\",\n              {\n                loader: \"css-loader\",\n                options: {\n                  // Other options\n                },\n              },\n            ],\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n\n## Examples\n\n### Recommend\n\nFor `production` builds, it's recommended to extract the CSS from your bundle being able to use parallel loading of CSS/JS resources later on.\n\nThis can be achieved by using the [mini-css-extract-plugin](https://github.com/webpack/mini-css-extract-plugin), because it creates separate css files.\n\nFor `development` mode (including `webpack-dev-server`) you can use [style-loader](https://github.com/webpack/style-loader), because it injects CSS into the DOM using multiple `<style></style>` and works faster.\n\n> [!NOTE]\n>\n> Do not use `style-loader` and `mini-css-extract-plugin` together.\n\n**webpack.config.js**\n\n```js\nconst MiniCssExtractPlugin = require(\"mini-css-extract-plugin\");\nconst devMode = process.env.NODE_ENV !== \"production\";\n\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        // If you enable `experiments.css` or `experiments.futureDefaults`, please uncomment line below\n        // type: \"javascript/auto\",\n        test: /\\.(sa|sc|c)ss$/i,\n        use: [\n          devMode ? \"style-loader\" : MiniCssExtractPlugin.loader,\n          \"css-loader\",\n          \"postcss-loader\",\n          \"sass-loader\",\n        ],\n      },\n    ],\n  },\n  plugins: [].concat(devMode ? [] : [new MiniCssExtractPlugin()]),\n};\n```\n\n### Disable URL resolving using the `/* webpackIgnore: true */` comment\n\nWith the help of the `/* webpackIgnore: true */`comment, it is possible to disable sources handling for rules and for individual declarations.\n\n```css\n/* webpackIgnore: true */\n@import url(./basic.css);\n@import /* webpackIgnore: true */ url(./imported.css);\n\n.class {\n  /* Disabled url handling for the all urls in the 'background' declaration */\n  color: red;\n  /* webpackIgnore: true */\n  background: url(\"./url/img.png\"), url(\"./url/img.png\");\n}\n\n.class {\n  /* Disabled url handling for the first url in the 'background' declaration */\n  color: red;\n  background:\n    /* webpackIgnore: true */ url(\"./url/img.png\"), url(\"./url/img.png\");\n}\n\n.class {\n  /* Disabled url handling for the second url in the 'background' declaration */\n  color: red;\n  background:\n    url(\"./url/img.png\"),\n    /* webpackIgnore: true */ url(\"./url/img.png\");\n}\n\n/* prettier-ignore */\n.class {\n  /* Disabled url handling for the second url in the 'background' declaration */\n  color: red;\n  background: url(\"./url/img.png\"),\n    /* webpackIgnore: true */\n    url(\"./url/img.png\");\n}\n\n/* prettier-ignore */\n.class {\n  /* Disabled url handling for third and sixth urls in the 'background-image' declaration */\n  background-image: image-set(\n    url(./url/img.png) 2x,\n    url(./url/img.png) 3x,\n    /* webpackIgnore:  true */ url(./url/img.png) 4x,\n    url(./url/img.png) 5x,\n    url(./url/img.png) 6x,\n    /* webpackIgnore:  true */\n    url(./url/img.png) 7x\n  );\n}\n```\n\n### Assets\n\nThe following `webpack.config.js` can load CSS files, embed small PNG/JPG/GIF/SVG images as well as fonts as [Data URLs](https://tools.ietf.org/html/rfc2397) and copy larger files to the output directory.\n\n**For webpack v5:**\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        use: [\"style-loader\", \"css-loader\"],\n      },\n      {\n        test: /\\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,\n        // More information here https://webpack.js.org/guides/asset-modules/\n        type: \"asset\",\n      },\n    ],\n  },\n};\n```\n\n### Extract\n\nFor production builds it's recommended to extract the CSS from your bundle to enable parallel loading of CSS/JS resources later on.\n\n- This can be achieved by using the [mini-css-extract-plugin](https://github.com/webpack/mini-css-extract-plugin) to extract the CSS when running in production mode.\n\n- As an alternative, if seeking better development performance and css outputs that mimic production. [extract-css-chunks-webpack-plugin](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin) offers a hot module reload friendly, extended version of mini-css-extract-plugin. HMR real CSS files in dev, works like mini-css in non-dev.\n\n### Pure CSS, CSS Modules and PostCSS\n\nWhen you have pure CSS (without CSS modules), CSS modules and PostCSS in your project, you can use this setup:\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        // For pure CSS - /\\.css$/i,\n        // For Sass/SCSS - /\\.((c|sa|sc)ss)$/i,\n        // For Less - /\\.((c|le)ss)$/i,\n        test: /\\.((c|sa|sc)ss)$/i,\n        use: [\n          \"style-loader\",\n          {\n            loader: \"css-loader\",\n            options: {\n              // Run `postcss-loader` on each CSS `@import` and CSS modules/ICSS imports, do not forget that `sass-loader` compile non CSS `@import`'s into a single file\n              // If you need run `sass-loader` and `postcss-loader` on each CSS `@import` please set it to `2`\n              importLoaders: 1,\n            },\n          },\n          {\n            loader: \"postcss-loader\",\n            options: { plugins: () => [postcssPresetEnv({ stage: 0 })] },\n          },\n          // Can be `less-loader`\n          {\n            loader: \"sass-loader\",\n          },\n        ],\n      },\n      // For webpack v5\n      {\n        test: /\\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,\n        // More information here https://webpack.js.org/guides/asset-modules/\n        type: \"asset\",\n      },\n    ],\n  },\n};\n```\n\n### Resolve unresolved URLs using an alias\n\n**index.css**\n\n```css\n.class {\n  background: url(/assets/unresolved/img.png);\n}\n```\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        use: [\"style-loader\", \"css-loader\"],\n      },\n    ],\n  },\n  resolve: {\n    alias: {\n      \"/assets/unresolved/img.png\": path.resolve(\n        __dirname,\n        \"assets/real-path-to-img/img.png\",\n      ),\n    },\n  },\n};\n```\n\n### Named export with custom export names\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        loader: \"css-loader\",\n        options: {\n          modules: {\n            namedExport: true,\n            exportLocalsConvention: function (name) {\n              return name.replace(/-/g, \"_\");\n            },\n          },\n        },\n      },\n    ],\n  },\n};\n```\n\n### Separating `Interoperable CSS`-only and `CSS Module` features\n\nThe following setup is an example of allowing `Interoperable CSS` features only (such as `:import` and `:export`) without using further `CSS Module` functionality by setting the `mode` option for all files that do not match the `*.module.scss` naming convention. This is for reference, as having `ICSS` features applied to all files was default `css-loader` behavior before v4.\n\nMeanwhile, all files matching `*.module.scss` are treated as `CSS Modules` in this example.\n\nAn 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).\n\n**webpack.config.js**\n\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      // ...\n      // --------\n      // SCSS ALL EXCEPT MODULES\n      {\n        test: /\\.scss$/i,\n        exclude: /\\.module\\.scss$/i,\n        use: [\n          {\n            loader: \"style-loader\",\n          },\n          {\n            loader: \"css-loader\",\n            options: {\n              importLoaders: 1,\n              modules: {\n                mode: \"icss\",\n              },\n            },\n          },\n          {\n            loader: \"sass-loader\",\n          },\n        ],\n      },\n      // --------\n      // SCSS MODULES\n      {\n        test: /\\.module\\.scss$/i,\n        use: [\n          {\n            loader: \"style-loader\",\n          },\n          {\n            loader: \"css-loader\",\n            options: {\n              importLoaders: 1,\n              modules: {\n                mode: \"local\",\n              },\n            },\n          },\n          {\n            loader: \"sass-loader\",\n          },\n        ],\n      },\n      // --------\n      // ...\n    ],\n  },\n};\n```\n\n**variables.scss**\n\nFile treated as `ICSS`-only.\n\n```scss\n$colorBackground: red;\n:export {\n  colorBackgroundCanvas: $colorBackground;\n}\n```\n\n**Component.module.scss**\n\nFile treated as `CSS Module`.\n\n```scss\n@import \"variables.scss\";\n.componentClass {\n  background-color: $colorBackground;\n}\n```\n\n**Component.jsx**\n\nUsing both `CSS Module` functionality as well as SCSS variables directly in JavaScript.\n\n```jsx\nimport * as svars from \"variables.scss\";\nimport * as styles from \"Component.module.scss\";\n\n// Render DOM with CSS modules class name\n// <div className={styles.componentClass}>\n//   <canvas ref={mountsCanvas}/>\n// </div>\n\n// Somewhere in JavaScript canvas drawing code use the variable directly\n// const ctx = mountsCanvas.current.getContext('2d',{alpha: false});\nctx.fillStyle = `${svars.colorBackgroundCanvas}`;\n```\n\n## Contributing\n\nWe welcome all contributions!\n\nIf you are new here, please take a moment to review our contributing guidelines before submitting issues or pull requests.\n\n[CONTRIBUTING](https://github.com/webpack/css-loader?tab=contributing-ov-file#contributing)\n\n## License\n\n[MIT](./LICENSE)\n\n[npm]: https://img.shields.io/npm/v/css-loader.svg\n[npm-url]: https://npmjs.com/package/css-loader\n[node]: https://img.shields.io/node/v/css-loader.svg\n[node-url]: https://nodejs.org\n[tests]: https://github.com/webpack/css-loader/workflows/css-loader/badge.svg\n[tests-url]: https://github.com/webpack/css-loader/actions\n[cover]: https://codecov.io/gh/webpack/css-loader/branch/main/graph/badge.svg\n[cover-url]: https://codecov.io/gh/webpack/css-loader\n[discussion]: https://img.shields.io/github/discussions/webpack/webpack\n[discussion-url]: https://github.com/webpack/webpack/discussions\n[size]: https://packagephobia.now.sh/badge?p=css-loader\n[size-url]: https://packagephobia.now.sh/result?p=css-loader\n","publish_time":1771248477741,"_cnpm_publish_time":1771248477741,"dist-tags":{"latest":"7.1.5"}}