{"id":14964133,"url":"https://github.com/nuxt/css-loader","last_synced_at":"2025-09-30T19:30:56.048Z","repository":{"id":65982872,"uuid":"101087751","full_name":"nuxt/css-loader","owner":"nuxt","description":"css loader module for webpack","archived":false,"fork":true,"pushed_at":"2024-06-05T05:34:32.000Z","size":1025,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T09:37:41.938Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"webpack-contrib/css-loader","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nuxt.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-22T17:09:10.000Z","updated_at":"2024-03-11T02:38:25.000Z","dependencies_parsed_at":"2023-02-19T18:31:14.786Z","dependency_job_id":null,"html_url":"https://github.com/nuxt/css-loader","commit_stats":null,"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"purl":"pkg:github/nuxt/css-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt%2Fcss-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt%2Fcss-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt%2Fcss-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt%2Fcss-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuxt","download_url":"https://codeload.github.com/nuxt/css-loader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt%2Fcss-loader/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277746958,"owners_count":25870057,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-30T02:00:09.208Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T13:32:37.226Z","updated_at":"2025-09-30T19:30:55.674Z","avatar_url":"https://github.com/nuxt.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm][npm]][npm-url]\n[![node][node]][node-url]\n[![deps][deps]][deps-url]\n[![tests][tests]][tests-url]\n[![coverage][cover]][cover-url]\n[![chat][chat]][chat-url]\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"180\" height=\"180\" vspace=\"20\"\n    src=\"https://cdn.worldvectorlogo.com/logos/css-3.svg\"\u003e\n  \u003ca href=\"https://github.com/webpack/webpack\"\u003e\n    \u003cimg width=\"200\" height=\"200\"\n      src=\"https://webpack.js.org/assets/icon-square-big.svg\"\u003e\n  \u003c/a\u003e\n  \u003ch1\u003eCSS Loader\u003c/h1\u003e\n\u003c/div\u003e\n\n\u003ch2 align=\"center\"\u003eInstall\u003c/h2\u003e\n\n```bash\nnpm install --save-dev css-loader\n```\n\n\u003ch2 align=\"center\"\u003eUsage\u003c/h2\u003e\n\nThe `css-loader` interprets `@import` and `url()` like `import/require()`\nand will resolve them.\n\nGood loaders for requiring your assets are the [file-loader](https://github.com/webpack/file-loader)\nand the [url-loader](https://github.com/webpack/url-loader) which you should specify in your config (see [below](https://github.com/webpack-contrib/css-loader#assets)).\n\n**file.js**\n```js\nimport css from 'file.css';\n```\n\n**webpack.config.js**\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/,\n        use: [ 'style-loader', 'css-loader' ]\n      }\n    ]\n  }\n}\n```\n\n### `toString`\n\nYou can also use the css-loader results directly as string, such as in Angular's component style.\n\n**webpack.config.js**\n```js\n{\n   test: /\\.css$/,\n   use: [\n     'to-string-loader',\n     'css-loader'\n   ]\n}\n```\n\nor\n\n```js\nconst css = require('./test.css').toString();\n\nconsole.log(css); // {String}\n```\n\nIf there are SourceMaps, they will also be included in the result string.\n\nIf, for one reason or another, you need to extract CSS as a\nplain string resource (i.e. not wrapped in a JS module) you\nmight want to check out the [extract-loader](https://github.com/peerigon/extract-loader).\nIt's useful when you, for instance, need to post process the CSS as a string.\n\n**webpack.config.js**\n```js\n{\n   test: /\\.css$/,\n   use: [\n     'handlebars-loader', // handlebars loader expects raw resource string\n     'extract-loader',\n     'css-loader'\n   ]\n}\n```\n\n\u003ch2 align=\"center\"\u003eOptions\u003c/h2\u003e\n\n|Name|Type|Default|Description|\n|:--:|:--:|:-----:|:----------|\n|**`root`**|`{String}`|`/`|Path to resolve URLs, URLs starting with `/` will not be translated|\n|**`url`**|`{Boolean}`|`true`| Enable/Disable `url()` handling|\n|**`alias`**|`{Object}`|`{}`|Create aliases to import certain modules more easily|\n|**`import`** |`{Boolean}`|`true`| Enable/Disable @import handling|\n|**`modules`**|`{Boolean}`|`false`|Enable/Disable CSS Modules|\n|**`minimize`**|`{Boolean\\|Object}`|`false`|Enable/Disable minification|\n|**`sourceMap`**|`{Boolean}`|`false`|Enable/Disable Sourcemaps|\n|**`camelCase`**|`{Boolean\\|String}`|`false`|Export Classnames in CamelCase|\n|**`importLoaders`**|`{Number}`|`0`|Number of loaders applied before CSS loader|\n|**`localIdentName`**|`{String}`|`[hash:base64]`|Configure the generated ident|\n\n### `root`\n\nFor URLs that start with a `/`, the default behavior is to not translate them.\n\n`url(/image.png) =\u003e url(/image.png)`\n\nIf a `root` query parameter is set, however, it will be prepended to the URL\nand then translated.\n\n**webpack.config.js**\n```js\n{\n  loader: 'css-loader',\n  options: { root: '.' }\n}\n```\n\n`url(/image.png)` =\u003e `require('./image.png')`\n\nUsing 'Root-relative' urls is not recommended. You should only use it for legacy CSS files.\n\n### `url`\n\nTo disable `url()` resolving by `css-loader` set the option to `false`.\n\nTo be compatible with existing css files (if not in CSS Module mode).\n\n```\nurl(image.png) =\u003e require('./image.png')\nurl(~module/image.png) =\u003e require('module/image.png')\n```\n\n### `alias`\n\nRewrite your urls with alias, this is useful when it's hard to change url paths of your input files, for example, when you're using some css / sass files in another package (bootstrap, ratchet, font-awesome, etc.).\n\n`css-loader`'s `alias` follows the same syntax as webpack's `resolve.alias`, you can see the details at the [resolve docs] (https://webpack.js.org/configuration/resolve/#resolve-alias)\n\n**file.scss**\n```css\n@charset \"UTF-8\";\n@import \"bootstrap\";\n```\n\n**webpack.config.js**\n```js\n{\n  test: /\\.scss$/,\n  use: [\n    {\n      loader: \"style-loader\"\n    },\n    {\n      loader: \"css-loader\",\n      options: {\n        alias: {\n          \"../fonts/bootstrap\": \"bootstrap-sass/assets/fonts/bootstrap\"\n        }\n      }\n    },\n    {\n      loader: \"sass-loader\",\n      options: {\n        includePaths: [\n          path.resolve(\"./node_modules/bootstrap-sass/assets/stylesheets\")\n        ]\n      }\n    }\n  ]\n}\n```\n\nCheck out this [working bootstrap example](https://github.com/bbtfr/webpack2-bootstrap-sass-sample).\n\n### `import`\n\nTo disable `@import` resolving by `css-loader` set the option to `false`\n\n```css\n@import url('https://fonts.googleapis.com/css?family=Roboto');\n```\n\n\u003e _⚠️ Use with caution, since this disables resolving for **all** `@import`s, including css modules `composes: xxx from 'path/to/file.css'` feature._\n\n### [`modules`](https://github.com/css-modules/css-modules)\n\nThe query parameter `modules` enables the **CSS Modules** spec.\n\nThis enables local scoped CSS by default. (You can switch it off with `:global(...)` or `:global` for selectors and/or rules.).\n\n#### `Scope`\n\nBy default CSS exports all classnames into a global selector scope. Styles can be locally scoped to avoid globally scoping styles.\n\nThe syntax `:local(.className)` can be used to declare `className` in the local scope. The local identifiers are exported by the module.\n\nWith `:local` (without brackets) local mode can be switched on for this selector. `:global(.className)` can be used to declare an explicit global selector. With `:global` (without brackets) global mode can be switched on for this selector.\n\nThe loader replaces local selectors with unique identifiers. The choosen unique identifiers are exported by the module.\n\n```css\n:local(.className) { background: red; }\n:local .className { color: green; }\n:local(.className .subClass) { color: green; }\n:local .className .subClass :global(.global-class-name) { color: blue; }\n```\n\n```css\n._23_aKvs-b8bW2Vg3fwHozO { background: red; }\n._23_aKvs-b8bW2Vg3fwHozO { color: green; }\n._23_aKvs-b8bW2Vg3fwHozO ._13LGdX8RMStbBE9w-t0gZ1 { color: green; }\n._23_aKvs-b8bW2Vg3fwHozO ._13LGdX8RMStbBE9w-t0gZ1 .global-class-name { color: blue; }\n```\n\n\u003e :information_source: Identifiers are exported\n\n```js\nexports.locals = {\n  className: '_23_aKvs-b8bW2Vg3fwHozO',\n  subClass: '_13LGdX8RMStbBE9w-t0gZ1'\n}\n```\n\nCamelCase is recommended for local selectors. They are easier to use in the within the imported JS module.\n\n`url()` URLs in block scoped (`:local .abc`) rules behave like requests in modules.\n\n```\nfile.png =\u003e ./file.png\n~module/file.png =\u003e module/file.png\n```\n\nYou can use `:local(#someId)`, but this is not recommended. Use classes instead of ids.\nYou can configure the generated ident with the `localIdentName` query parameter (default `[hash:base64]`).\n\n **webpack.config.js**\n ```js\n{\n  test: /\\.css$/,\n  use: [\n    {\n      loader: 'css-loader',\n      options: {\n        modules: true,\n        localIdentName: '[path][name]__[local]--[hash:base64:5]'\n      }\n    }\n  ]\n}\n```\n\nYou can also specify the absolute path to your custom `getLocalIdent` function to generate classname based on a different schema. This requires `webpack \u003e= 2.2.1` (it supports functions in the `options` object).\n\n**webpack.config.js**\n```js\n{\n  loader: 'css-loader',\n  options: {\n    modules: true,\n    localIdentName: '[path][name]__[local]--[hash:base64:5]',\n    getLocalIdent: (context, localIdentName, localName, options) =\u003e {\n      return 'whatever_random_class_name'\n    }\n  }\n}\n```\n\n\u003e :information_source: For prerendering with extract-text-webpack-plugin you should use `css-loader/locals` instead of `style-loader!css-loader` **in the prerendering bundle**. It doesn't embed CSS but only exports the identifier mappings.\n\n#### `Composing`\n\nWhen declaring a local classname you can compose a local class from another local classname.\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 doesn't result in any change to the CSS itself but exports multiple classnames.\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 classname from another module.\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: edit hightlight from './edit.css';\n  composes: button from 'module/button.css';\n  composes: classFromThisModule;\n  background: red;\n}\n```\n\n### `minimize`\n\nBy default the css-loader minimizes the css if specified by the module system.\n\nIn some cases the minification is destructive to the css, so you can provide your own options to the cssnano-based minifier if needed. See [cssnano's documentation](http://cssnano.co/guides/) for more information on the available options.\n\nYou can also disable or enforce minification with the `minimize` query parameter.\n\n**webpack.config.js**\n```js\n{\n  loader: 'css-loader',\n  options: {\n    minimize: true || {/* CSSNano Options */}\n  }\n}\n```\n\n### `sourceMap`\n\nTo include source maps set the `sourceMap` option.\n\nI. e. the extract-text-webpack-plugin can handle them.\n\nThey are not enabled by default because they expose a runtime overhead and increase in bundle size (JS source maps do not). In addition to that relative paths are buggy and you need to use an absolute public path which include the server URL.\n\n**webpack.config.js**\n```js\n{\n  loader: 'css-loader',\n  options: {\n    sourceMap: true\n  }\n}\n```\n\n### `camelCase`\n\nBy default, the exported JSON keys mirror the class names. If you want to camelize class names (useful in JS), pass the query parameter `camelCase` to css-loader.\n\n|Name|Type|Description|\n|:--:|:--:|:----------|\n|**`true`**|`{Boolean}`|Class names will be camelized|\n|**`'dashes'`**|`{String}`|Only dashes in class names will be camelized|\n|**`'only'`** |`{String}`|Introduced in `0.27.1`. Class names will be camelized, the original class name will be removed from the locals|\n|**`'dashesOnly'`**|`{String}`|Introduced in `0.27.1`. Dashes in class names will be camelized, the original class name will be removed from the locals|\n\n**file.css**\n```css\n.class-name {}\n```\n\n**file.js**\n```js\nimport { className } from 'file.css';\n```\n\n**webpack.config.js**\n```js\n{\n  loader: 'css-loader',\n  options: {\n    camelCase: true\n  }\n}\n```\n\n### `importLoaders`\n\nThe query parameter `importLoaders` allows to configure how many loaders before `css-loader` should be applied to `@import`ed resources.\n\n**webpack.config.js**\n```js\n{\n  test: /\\.css$/,\n  use: [\n    'style-loader',\n    {\n      loader: 'css-loader',\n      options: {\n        importLoaders: 1 // 0 =\u003e no loaders (default); 1 =\u003e postcss-loader; 2 =\u003e postcss-loader, sass-loader\n      }\n    },\n    'postcss-loader',\n    'sass-loader'\n  ]\n}\n```\n\nThis may change in the future, when the module system (i. e. webpack) supports loader matching by origin.\n\n\u003ch2 align=\"center\"\u003eExamples\u003c/h2\u003e\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**webpack.config.js**\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/,\n        use: [ 'style-loader', 'css-loader' ]\n      },\n      {\n        test: /\\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,\n        loader: 'url-loader',\n        options: {\n          limit: 10000\n        }\n      }\n    ]\n  }\n}\n```\n\n### Extract\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. This can be achieved by using the [extract-text-webpack-plugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) to extract the CSS when running in production mode.\n\n**webpack.config.js**\n```js\nconst env = process.env.NODE_ENV\n\nconst ExtractTextPlugin = require('extract-text-webpack-plugin')\n\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/,\n        use: env === 'production'\n          ? ExtractTextPlugin.extract({\n              fallback: 'style-loader',\n              use: [ 'css-loader' ]\n          })\n          : [ 'style-loader', 'css-loader' ]\n      },\n    ]\n  },\n  plugins: env === 'production'\n    ? [\n        new ExtractTextPlugin({\n          filename: '[name].css'\n        })\n      ]\n    : []\n}\n```\n\n\u003ch2 align=\"center\"\u003eMaintainers\u003c/h2\u003e\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://github.com/bebraw.png?v=3\u0026s=150\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/bebraw\"\u003eJuho Vepsäläinen\u003c/a\u003e\n      \u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://github.com/d3viant0ne.png?v=3\u0026s=150\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/d3viant0ne\"\u003eJoshua Wiens\u003c/a\u003e\n      \u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://github.com/SpaceK33z.png?v=3\u0026s=150\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/SpaceK33z\"\u003eKees Kluskens\u003c/a\u003e\n      \u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://github.com/TheLarkInn.png?v=3\u0026s=150\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/TheLarkInn\"\u003eSean Larkin\u003c/a\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://github.com/michael-ciniawsky.png?v=3\u0026s=150\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/michael-ciniawsky\"\u003eMichael Ciniawsky\u003c/a\u003e\n      \u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://github.com/evilebottnawi.png?v=3\u0026s=150\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/evilebottnawi\"\u003eEvilebot Tnawi\u003c/a\u003e\n      \u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://github.com/joscha.png?v=3\u0026s=150\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/joscha\"\u003eJoscha Feth\u003c/a\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003ctbody\u003e\n\u003c/table\u003e\n\n\n[npm]: https://img.shields.io/npm/v/css-loader.svg\n[npm-url]: https://npmjs.com/package/css-loader\n\n[node]: https://img.shields.io/node/v/css-loader.svg\n[node-url]: https://nodejs.org\n\n[deps]: https://david-dm.org/webpack-contrib/css-loader.svg\n[deps-url]: https://david-dm.org/webpack-contrib/css-loader\n\n[tests]: http://img.shields.io/travis/webpack-contrib/css-loader.svg\n[tests-url]: https://travis-ci.org/webpack-contrib/css-loader\n\n[cover]: https://codecov.io/gh/webpack-contrib/css-loader/branch/master/graph/badge.svg\n[cover-url]: https://codecov.io/gh/webpack-contrib/css-loader\n\n[chat]: https://badges.gitter.im/webpack/webpack.svg\n[chat-url]: https://gitter.im/webpack/webpack\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxt%2Fcss-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuxt%2Fcss-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxt%2Fcss-loader/lists"}