{"id":15250449,"url":"https://github.com/waivital/auto-css-modules-webpack-plugin","last_synced_at":"2025-04-10T19:41:42.409Z","repository":{"id":57187234,"uuid":"339757704","full_name":"waivital/auto-css-modules-webpack-plugin","owner":"waivital","description":"Automatically detect and mark CSS modules for webpack.","archived":false,"fork":false,"pushed_at":"2025-02-17T03:04:29.000Z","size":473,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T17:21:15.698Z","etag":null,"topics":["css-modules","webpack","webpack-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/waivital.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-17T14:55:10.000Z","updated_at":"2025-02-17T03:04:33.000Z","dependencies_parsed_at":"2024-06-21T15:44:28.011Z","dependency_job_id":"be1519b8-dba8-4fdd-8bf3-8ee6a72397e1","html_url":"https://github.com/waivital/auto-css-modules-webpack-plugin","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waivital%2Fauto-css-modules-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waivital%2Fauto-css-modules-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waivital%2Fauto-css-modules-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waivital%2Fauto-css-modules-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waivital","download_url":"https://codeload.github.com/waivital/auto-css-modules-webpack-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281415,"owners_count":21077423,"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","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":["css-modules","webpack","webpack-plugin"],"created_at":"2024-09-29T16:04:53.787Z","updated_at":"2025-04-10T19:41:42.389Z","avatar_url":"https://github.com/waivital.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Auto CSS Modules Webpack Plugin\n\nAutomatically detect and mark CSS modules for webpack.\n\n[![npm][npm]][npm-url]\n\n\u003e *Read this in other languages: [English](README.md), [简体中文](README_CN.md)*\n\n## Installation\n\nFor npm\n```bash\nnpm install --save-dev auto-css-modules-webpack-plugin\n```\n\nFor yarn\n```bash\nyarn add -D auto-css-modules-webpack-plugin\n```\n\n## Usage\n\n\u003e For a complete example, please check [examples](https://github.com/waivital/auto-css-modules-webpack-plugin/tree/main/examples)\n\nconfig with `css-loader`\n\n**webpack.config.js**\n\n```javascript\nconst AutoCSSModulesWebpackPlugin = require('auto-css-modules-webpack-plugin')\n\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.css$/i,\n        oneOf: [\n          {\n            // enable cssModules for specific resourceQuery\n            resourceQuery: /modules/,\n            use: [\n              'style-loader',\n              {\n                loader: 'css-loader',\n                options: {\n                  importLoaders: 0,\n                  // Enable CSS Modules features and setup options for them.\n                  modules: {\n                    localIdentName: '[path][name]__[local]--[hash:base64:5]',\n                    // ... Other options\n                  }\n                }\n              }\n            ]\n          },\n          {\n            use: [\n              'style-loader',\n              {\n                loader: 'css-loader',\n                options: {\n                  importLoaders: 0,\n                }\n              }\n            ]\n          },\n        ],\n      },\n    ],\n  },\n  // Add this plugin\n  plugins: [new AutoCSSModulesWebpackPlugin()]\n};\n```\n\nThe following statements will be marked as CSS Modules\n\n```js\nimport styles from './index.css'\n// Or\nconst styles = require('./index.css')\n// Or\nconst styles = _anyFunctionWrap(require('./index.css'))\n// Or\nconst styles = require('./index.css').default\n```\n\n## Options\n\nYou can pass an options object to AutoCSSModulesWebpackPlugin. Allowed values are as follows:\n\n|        Name         |     Type     |   Default   | Description                                        |\n| :-----------------: | :----------: | :---------: | :------------------------------------------------- |\n|   **`queryFlag`**   |  `{string}`  | `'modules'` | The resource query will add to the request string  |\n| **`extraExtnames`** | `{string[]}` |    `[]`     | More extnames are needed to consider as style file |\n\nDefault extname list is `['.css', '.less', '.sass', '.scss', '.stylus', '.styl']`, cannot be overwrite currently.\n\n## How it works\n\nBecause the usage scenario of CSS Modules always needs `import` or `require` a CSS file then bind it to a variable, so we can analyze the ast of the file, when it matches this pattern, add a query to the request string.\n\nFor example, `import styles from './index.css'` will be converted to `import styles from'./index.css?modules'`\n\nAnd a [hook](https://webpack.js.org/api/parser/#program) `parser.hooks.program` inside webpack allows us to modify the ast of the file before it actually parses the dependencies.\n\nThen we can use `resourceQuery` to pass different options to the loader, one for normal CSS and one for CSS Modules.\n\n## Thanks\n\nInspired by [@umijs/babel-plugin-auto-css-modules](https://www.npmjs.com/package/@umijs/babel-plugin-auto-css-modules)\n\n\n## License\n\n[MIT](./LICENSE)\n\n[npm]: https://img.shields.io/npm/v/auto-css-modules-webpack-plugin.svg\n[npm-url]: https://npmjs.com/package/auto-css-modules-webpack-plugin\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaivital%2Fauto-css-modules-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaivital%2Fauto-css-modules-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaivital%2Fauto-css-modules-webpack-plugin/lists"}