{"id":19176117,"url":"https://github.com/fengxinming/chain-css-loader","last_synced_at":"2025-04-20T01:32:16.283Z","repository":{"id":57196634,"uuid":"191773898","full_name":"fengxinming/chain-css-loader","owner":"fengxinming","description":"Easy to use stylus、less and sass in umijs2 or create-react-app.","archived":false,"fork":false,"pushed_at":"2019-10-22T07:26:41.000Z","size":357,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2025-04-18T14:21:38.245Z","etag":null,"topics":["create-react-app","css-loader","less","sass","stylus","stylus-loader","umijs","webpack"],"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/fengxinming.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-06-13T14:00:58.000Z","updated_at":"2023-03-10T12:03:32.000Z","dependencies_parsed_at":"2022-09-01T00:52:35.847Z","dependency_job_id":null,"html_url":"https://github.com/fengxinming/chain-css-loader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengxinming%2Fchain-css-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengxinming%2Fchain-css-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengxinming%2Fchain-css-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengxinming%2Fchain-css-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fengxinming","download_url":"https://codeload.github.com/fengxinming/chain-css-loader/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249838125,"owners_count":21332561,"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":["create-react-app","css-loader","less","sass","stylus","stylus-loader","umijs","webpack"],"created_at":"2024-11-09T10:27:14.552Z","updated_at":"2025-04-20T01:32:15.966Z","avatar_url":"https://github.com/fengxinming.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chain-css-loader\n\n\u003e 简化在 [umi](https://github.com/umijs/umi) 和 [create-react-app](https://github.com/facebook/create-react-app) 中使用 [stylus](http://stylus-lang.com/), 也支持`less`和`sass`.(目前支持 css-loader@2)\n\n[![npm package](https://nodei.co/npm/chain-css-loader.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://www.npmjs.com/package/chain-css-loader) [![NPM version](https://img.shields.io/npm/v/chain-css-loader.svg?style=flat)](https://npmjs.org/package/chain-css-loader) [![NPM Downloads](https://img.shields.io/npm/dm/chain-css-loader.svg?style=flat)](https://npmjs.org/package/chain-css-loader)\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\u003c/div\u003e\n\n---\n\n## 目录\n\n  - [安装](#安装)\n  - [API 相关](#API-相关)\n  - [使用说明](#使用说明)\n    - [在 umijs 中使用添加stylus支持](#在-umijs-中使用添加stylus支持)\n    - [在 create-react-app 中使用添加stylus支持](#在-create-react-app-中使用添加stylus支持)\n  - [使用事例](#使用事例)\n  - [更新记录](#更新记录)\n\n---\n\n## 安装\n\n```\nnpm install chain-css-loader --save-dev\n```\n\n---\n\n## API-相关\n\n* chain-css-loader\n  * UmiRule\n    * new UmiRule( webpackChain [, options] )\n      * _instance_\n        * useStylus() ⇒ \u003ccode\u003eUmiRule\u003c/code\u003e\n        * useLess() ⇒ \u003ccode\u003eUmiRule\u003c/code\u003e\n        * useSass() ⇒ \u003ccode\u003eUmiRule\u003c/code\u003e\n        * useCss() ⇒ \u003ccode\u003eUmiRule\u003c/code\u003e\n        * extractCss() ⇒ \u003ccode\u003eUmiRule\u003c/code\u003e\n\n      * _static_\n  * RewiredRule\n    * new RewiredRule( webpackConfig [, options] )\n      * _instance_\n        * useStylus() ⇒ \u003ccode\u003eRewiredRule\u003c/code\u003e\n        * useLess() ⇒ \u003ccode\u003eRewiredRule\u003c/code\u003e\n        * useSass() ⇒ \u003ccode\u003eRewiredRule\u003c/code\u003e\n        * useCss() ⇒ \u003ccode\u003eRewiredRule\u003c/code\u003e\n        * extractCss() ⇒ \u003ccode\u003eRewiredRule\u003c/code\u003e\n\n      * _static_\n\n`new UmiRule`\n\n* 可选参数\n  * `cssPublicPath` 默认 '/', css在浏览器中被访问的跟路径\n  * `cwd` 默认 `process.cwd()`\n  * `modulesWithAffix` 默认 true, 对 *.module.[ext] 结尾的文件启用 CSS Modules\n  * `modules` 默认 false, 只对 *.module.[ext] 结尾的文件启用 CSS Modules; 如果设置为 true, 对所有 *.(css|scss|sass|less|styl(us)?) 启用 CSS Modules\n  * `sourceMap` 默认 true, 是否生成 .map 文件, 只在非开发环境生效\n  * `compress` 默认 true, 是否压缩css, 只在非开发环境生效\n  * `usePoststylus` 默认 false, 是否自行使用 poststylus 插件替换内置 postcss-loader\n  * `autoprefixer`\n    * `browsers` 浏览器兼容版本, 建议配置在 `.browserslistrc` 文件中\n    * `flexbox` 默认 `no-2009`\n  * `compress` 压缩css配置\n    * `mergeRules` 默认 false,\n    * `normalizeUrl` 默认 false,\n    * `mergeLonghand` 默认 false,\n    * `cssDeclarationSorter` 默认 false\n  * `stylus` stylus-loader 配置\n    * `test` 默认 /\\.styl(us)?$/\n    * `modules` 默认 /\\.module\\.styl(us)?$/\n    * `loader` 默认 'stylus-loader'\n    * `options` stylus 配置参数\n  * `ssr` 跟 umijs 保持一致\n\n---\n\n## 使用说明\n\n### 在 umijs 中使用添加stylus支持\n\n```\nnpm install stylus stylus-loader --save-dev\n```\n\n#### 一般使用\n\n- 添加以下代码至 `.umirc.js`\n\n```\nimport { UmiRule } from 'chain-css-loader';\n\nexport default {\n  urlLoaderExcludes: [\n    /\\.styl$/,\n  ],\n  chainWebpack(config) {\n    const rule = new UmiRule(config, {\n      modules: true // start up CSS modules\n    });\n    rule.useStylus();\n    return config;\n  }\n}\n```\n\n#### 高级特性\n\n- 使用 [poststylus](https://github.com/seaneking/poststylus) 替换 [postcss](https://github.com/postcss/postcss)\n\n```\nnpm install poststylus postcss-flexbugs-fixes autoprefixer rucksack-css --save-dev\n```\n\n- 添加以下代码至 `.umirc.js`\n\n```\nimport poststylus from 'poststylus';\nimport { UmiRule } from 'chain-css-loader';\n\nexport default {\n  urlLoaderExcludes: [\n    /\\.styl$/,\n  ],\n  chainWebpack(config) {\n    const rule = new UmiRule(config, {\n      modules: true,\n      usePoststylus: true,\n      stylus: {\n        options: {\n          use: [\n            poststylus([\n              require('postcss-flexbugs-fixes'),\n              require('autoprefixer')({\n                flexbox: 'no-2009'\n              }),\n              'rucksack-css'\n            ])\n          ]\n        }\n      }\n    });\n    rule.useStylus();\n    return config;\n  }\n}\n```\n\n- 运行`umijs`时可能报 browserslist 相关警告，需要添加以下代码至 `.browserslistrc`\n\n```\n\u003e1%\nlast 4 versions\nFirefox ESR\nnot ie \u003c 9\n```\n\n### 在 create-react-app 中使用添加stylus支持\n\n```\nnpm install stylus stylus-loader --save-dev\n```\n\n#### 简单使用\n\n- 添加以下代码至 `config-overrides.js`, 前提是使用了`react-app-rewired`模块, 而不是导出webpack配置\n\n```\nconst { RewiredRule } = require('chain-css-loader');\n\nmodule.exports = {\n  webpack(config, env) {\n    const rule = new RewiredRule(config, {\n      modules: true\n    });\n    rule.useStylus();\n\n    return config;\n  }\n};\n```\n\n#### 高级特性\n\n- 使用 [poststylus](https://github.com/seaneking/poststylus) 替换 [postcss](https://github.com/postcss/postcss)\n\n```\nnpm install poststylus postcss-flexbugs-fixes autoprefixer rucksack-css --save-dev\n```\n\n- 添加以下代码至 `config-overrides.js`\n\n```\nconst poststylus = require('poststylus');\nconst { RewiredRule } = require('chain-css-loader');\n\nmodule.exports = {\n  webpack(config, env) {\n    const rule = new RewiredRule(config, {\n      modules: true,\n      usePoststylus: true,\n      stylus: {\n        options: {\n          use: [\n            poststylus([\n              require('postcss-flexbugs-fixes'),\n              require('autoprefixer')({\n                flexbox: 'no-2009'\n              }),\n              'rucksack-css'\n            ])\n          ]\n        }\n      }\n    });\n    rule.useStylus();\n\n    return config;\n  }\n};\n```\n\n---\n\n## 使用事例\n\n  - [umi](examples/umi)\n  - [create-react-app](examples/create-react-app)\n\n---\n\n## 更新记录\n\n  * 1.1.4\n    * 增加参数ssr，跟umijs保持一致\n\n  * 1.1.3\n    * 更新`lodash`\n\n  * 1.1.2\n    * 修复对`css-loader`传参问题\n  \n  * 1.1.1\n    * 修复对 CSS Modules 的支持问题\n\n  * 1.1.0\n    * 支持在`create-react-app`脚手架中使用`stylus`、`less`、`sass`等\n\n  * 1.0.0\n    * 支持在`umi`项目中使用`stylus`等\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffengxinming%2Fchain-css-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffengxinming%2Fchain-css-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffengxinming%2Fchain-css-loader/lists"}