{"id":25543455,"url":"https://github.com/ystarlongzi/fis3-hook-css-modules","last_synced_at":"2025-04-11T17:50:22.105Z","repository":{"id":57237195,"uuid":"87523613","full_name":"ystarlongzi/fis3-hook-css-modules","owner":"ystarlongzi","description":"基于fis3的css模块化方案","archived":false,"fork":false,"pushed_at":"2017-04-17T07:33:30.000Z","size":16,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T13:46:09.216Z","etag":null,"topics":["css-modules","fis3","loader"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ystarlongzi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-07T08:31:24.000Z","updated_at":"2021-03-21T11:20:19.000Z","dependencies_parsed_at":"2022-08-26T15:10:18.810Z","dependency_job_id":null,"html_url":"https://github.com/ystarlongzi/fis3-hook-css-modules","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ystarlongzi%2Ffis3-hook-css-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ystarlongzi%2Ffis3-hook-css-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ystarlongzi%2Ffis3-hook-css-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ystarlongzi%2Ffis3-hook-css-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ystarlongzi","download_url":"https://codeload.github.com/ystarlongzi/fis3-hook-css-modules/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248252718,"owners_count":21072701,"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","fis3","loader"],"created_at":"2025-02-20T07:19:31.961Z","updated_at":"2025-04-11T17:50:22.071Z","avatar_url":"https://github.com/ystarlongzi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"fis3-hook-css-modules\n=============================\n\n一款基于 fis3 的 [css modules](https://github.com/css-modules/css-modules) 插件。\n\n\n## 使用\n\n### 安装\n```\nnpm install fis3-hook-css-module\n```\n\n### 配置\n\n1. 如果项目中有使用 `Less`、`Sass`，你还需要借助 [fis-parser-less-2.x](https://github.com/fouber/fis-parser-less-2.x)、[fis-parser-node-sass](https://github.com/fex-team/fis-parser-node-sass) 插件。\n2. 你或许还需要借助 [fis3-postprocessor-postcss](https://github.com/jiangyuan/fis3-postprocessor-postcss) 插件，完成 css 属性补全等操作\n3. 此插件也具有 js-require-css 功能，所以你可能不需要在配置 [fis3-preprocessor-js-require-css](https://github.com/fex-team/fis3-preprocessor-js-require-css)\n\n\n```js\n// 将项目里的 less 文件转换为 css 文件\nfis.match('**.less', {\n    rExt: '.css',\n    parser: fis.plugin('less-2.x'),\n});\n\n// 将项目里的 sass 文件转换为 css 文件\nfis.match('**.{sass,scss}', {\n    rExt: '.css',\n    parser: fis.plugin('node-sass'),\n});\n\n// 进行 css 属性补全\nfis.match('**.{css,less,sass,scss}', {\n    postprocessor: fis.plugin('postcss'),\n});\n\n\n// ---- 配置 css modules\nfis.hook('css-modules', {\n  mode: 'inline',\n});\n```\n\n\n## 参数说明\n- `mode`：加载模式，默认为 `dep`\n    * `dep`\n    简单的标记依赖，并将js语句中对应的 `require` 语句去除。fis 的资源加载程序能够分析到这块，并最终以 `\u003clink\u003e` 的方式加载 css。\n    \n    * `inline` \n    将目标 css/less/scss 文件转换成 js 语句，并直接内嵌在当前 js 中，替换原有 `require` 语句。\n    \n    * `jsRequire` \n    将目标 css 文件转换成 js 语句，但是并不内嵌，而是产出一份同名的 js 文件，当前 `require` 语句替换成指向新产生的文件。\n\n\n- `scope`：定义 class 名称生成方式。类型可为 `[function | string]`\n    * 当类型为 `function` 时，会接受三个参数\n        * `name` 待被转化的 class 名称\n        * `file` 当前文件路径\n        * `css` 当前文件内容\n        \n    ```js\n    fis.hook('css-modules', {\n      scope: function (name, file, css) {\n        return (file + '__' + 'name' + '__');\n      },\n    });\n    ```\n  \n    * 当类型为 `string` 时，可以使用一些标记，如下:\n    ```js\n    fis.hook('css-modules', {\n      scope: '[name]__[local]___[hash:base64:5]',\n    });\n    ```\n    你可以在[这里](https://github.com/webpack/loader-utils#interpolatename)查看这些标记的含义。\n\n- `includePath`: 配置需要 scoped 的文件路径。类型为数组，支持 glob。\n\n- `excludePath`: 配置不需要 scoped 的文件路径，默认为 ['node_modeuls/**']。类型为数组，支持 glob。\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fystarlongzi%2Ffis3-hook-css-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fystarlongzi%2Ffis3-hook-css-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fystarlongzi%2Ffis3-hook-css-modules/lists"}