Skip to content

Commit a237ec3

Browse files
committed
feat(UmiRule): UmiRule 开发完成
1 parent b0535a6 commit a237ec3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1512
-1
lines changed

Diff for: .eslintrc

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"extends": [
3+
"standard"
4+
],
5+
"globals": {
6+
"describe": true,
7+
"it": true,
8+
"expect": true,
9+
"beforeAll": true,
10+
"afterAll": true
11+
},
12+
"rules": {
13+
"arrow-parens": [
14+
2,
15+
"as-needed",
16+
{
17+
"requireForBlockBody": true
18+
}
19+
],
20+
"padded-blocks": [
21+
"error",
22+
{
23+
"classes": "always"
24+
}
25+
],
26+
"indent": [
27+
"error",
28+
2,
29+
{
30+
"SwitchCase": 1,
31+
"flatTernaryExpressions": true
32+
}
33+
],
34+
"no-param-reassign": 0,
35+
"complexity": 0,
36+
"eqeqeq": [
37+
"error",
38+
"always"
39+
],
40+
"no-var": 2,
41+
"semi": [
42+
2,
43+
"always"
44+
],
45+
"space-before-function-paren": [
46+
"error",
47+
{
48+
"anonymous": "always",
49+
"named": "never",
50+
"asyncArrow": "always"
51+
}
52+
],
53+
"yoda": 0,
54+
"arrow-spacing": 2,
55+
"dot-location": [
56+
2,
57+
"property"
58+
],
59+
"prefer-arrow-callback": 2,
60+
"operator-linebreak": [
61+
2,
62+
"after",
63+
{
64+
"overrides": {
65+
"?": "ignore",
66+
":": "ignore"
67+
}
68+
}
69+
],
70+
"no-fallthrough": 0
71+
}
72+
}

Diff for: .npmignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.*.swp
2+
._*
3+
.DS_Store
4+
.git
5+
.hg
6+
.npmrc
7+
.lock-wscript
8+
.svn
9+
.wafpickle-*
10+
config.gypi
11+
CVS
12+
npm-debug.log
13+
coverage/
14+
examples/
15+
scripts/
16+
tests/

Diff for: README.md

+159-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,160 @@
1+
<div align="center">
2+
<img width="180" height="180" vspace="20"
3+
src="https://cdn.worldvectorlogo.com/logos/css-3.svg">
4+
<a href="https://github.com/webpack/webpack">
5+
<img width="200" height="200"
6+
src="https://webpack.js.org/assets/icon-square-big.svg">
7+
</a>
8+
</div>
9+
110
# chain-css-loader
2-
create css rule with webpack-chain
11+
12+
> create css rule with webpack-chain
13+
14+
[![npm package](https://nodei.co/npm/chain-css-loader.png?downloads=true&downloadRank=true&stars=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)
15+
16+
---
17+
18+
## Table of contents
19+
20+
- [Installation](#Installation)
21+
- [API Reference](#API-Reference)
22+
- [Usage](#Usage)
23+
- [Example for Umi](#Example-for-Umi)
24+
- [Sample](#Sample)
25+
- [Advanced Features](#Advanced-Features)
26+
- [Examples](#Examples)
27+
28+
---
29+
30+
## Installation
31+
32+
```
33+
npm install chain-css-loader --save-dev
34+
```
35+
36+
---
37+
38+
## API Reference
39+
40+
* chain-css-loader
41+
* UmiRule
42+
* new UmiRule( webpackConfig [, options] )
43+
* _instance_
44+
* useStylus() ⇒ <code>UmiRule</code>
45+
* useLess() ⇒ <code>UmiRule</code>
46+
* useSass() ⇒ <code>UmiRule</code>
47+
* useCss() ⇒ <code>UmiRule</code>
48+
* extractCss() ⇒ <code>UmiRule</code>
49+
50+
* _static_
51+
52+
These are the optional config options for <code>new UmiRule</code>
53+
54+
* optional options
55+
* `cwd` 默认 `process.cwd()`
56+
* `modulesWithAffix` 默认 true, 对 *.module.[ext] 结尾的文件启用 CSS Modules
57+
* `modules` 默认 false, 只对 *.module.[ext] 结尾的文件启用 CSS Modules; 如果设置为 true, 对所有 *.(css|scss|sass|less|styl(us)?) 启用 CSS Modules
58+
* `sourceMap` 默认 true, 是否生成 .map 文件, 只在非开发环境生效
59+
* `compress` 默认 true, 是否压缩css, 只在非开发环境生效
60+
* `usePoststylus` 默认 false, 是否自行使用 poststylus 插件替换内置 postcss-loader
61+
* `autoprefixer`
62+
* `browsers` 浏览器兼容版本, 建议配置在 `.browserslistrc` 文件中
63+
* `flexbox` 默认 `no-2009`
64+
* `compress` 压缩css配置
65+
* `mergeRules` 默认 false,
66+
* `normalizeUrl` 默认 false,
67+
* `mergeLonghand` 默认 false,
68+
* `cssDeclarationSorter` 默认 false
69+
* `stylus` stylus-loader 配置
70+
* `test` 默认 /\.styl(us)?$/
71+
* `loader` 默认 'stylus-loader'
72+
* `options` stylus 配置参数
73+
74+
---
75+
76+
## Usage
77+
78+
### Example for Umi
79+
80+
- Below is an example for using [stylus](https://github.com/stylus/stylus) in [umi](https://github.com/umijs/umi)
81+
82+
```
83+
npm install stylus stylus-loader --save-dev
84+
```
85+
86+
#### Sample
87+
88+
- Write the following code to the file `.umirc.js` or `.umirc.local.js`
89+
90+
```
91+
import { UmiRule } from 'chain-css-loader';
92+
93+
export default {
94+
urlLoaderExcludes: [
95+
/\.styl$/,
96+
],
97+
chainWebpack(config) {
98+
const rule = new UmiRule(config, {
99+
modules: true // start up CSS modules
100+
});
101+
rule.useStylus();
102+
}
103+
}
104+
```
105+
106+
#### Advanced Features
107+
108+
- Use [poststylus](https://github.com/seaneking/poststylus) instead of [postcss](https://github.com/postcss/postcss)
109+
110+
```
111+
npm install poststylus postcss-flexbugs-fixes autoprefixer rucksack-css --save-dev
112+
```
113+
114+
- Put the following code in the file `.umirc.js` or `.umirc.local.js`
115+
116+
```
117+
import poststylus from 'poststylus';
118+
import { UmiRule } from 'chain-css-loader';
119+
120+
export default {
121+
urlLoaderExcludes: [
122+
/\.styl$/,
123+
],
124+
chainWebpack(config) {
125+
const rule = new UmiRule(config, {
126+
modules: true,
127+
usePoststylus: true,
128+
stylus: {
129+
options: {
130+
use: [
131+
poststylus([
132+
require('postcss-flexbugs-fixes'),
133+
require('autoprefixer')({
134+
flexbox: 'no-2009'
135+
}),
136+
'rucksack-css'
137+
])
138+
]
139+
}
140+
}
141+
});
142+
rule.useStylus();
143+
}
144+
}
145+
```
146+
147+
- Copy the following code to the file `.browserslistrc` if it exists, or create a new file named `.browserslistrc` and then put below in the file
148+
149+
```
150+
>1%
151+
last 4 versions
152+
Firefox ESR
153+
not ie < 9
154+
```
155+
156+
---
157+
158+
## Examples
159+
160+
- [umi](examples/umi)

Diff for: examples/create-react-app/.browserslistrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
>1%
2+
last 4 versions
3+
Firefox ESR
4+
not ie < 9

Diff for: examples/create-react-app/.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

Diff for: examples/create-react-app/README.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `npm start`
8+
9+
Runs the app in the development mode.<br>
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br>
13+
You will also see any lint errors in the console.
14+
15+
### `npm test`
16+
17+
Launches the test runner in the interactive watch mode.<br>
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `npm run build`
21+
22+
Builds the app for production to the `build` folder.<br>
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br>
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `npm run eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35+
36+
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37+
38+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39+
40+
## Learn More
41+
42+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43+
44+
To learn React, check out the [React documentation](https://reactjs.org/).
45+
46+
### Code Splitting
47+
48+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49+
50+
### Analyzing the Bundle Size
51+
52+
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53+
54+
### Making a Progressive Web App
55+
56+
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57+
58+
### Advanced Configuration
59+
60+
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61+
62+
### Deployment
63+
64+
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65+
66+
### `npm run build` fails to minify
67+
68+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

Diff for: examples/create-react-app/config-overrides.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { join } = require('path');
2+
const { override, fixBabelImports, addWebpackAlias } = require('customize-cra');
3+
const { Rule } = require('../../index');
4+
5+
const resolve = (dir) => join(__dirname, '.', dir);
6+
7+
module.exports = function (config, env) {
8+
return override(
9+
addWebpackAlias({
10+
'~': resolve('src')
11+
}),
12+
fixBabelImports('import', {
13+
libraryName: 'antd',
14+
libraryDirectory: 'es',
15+
style: 'css'
16+
}),
17+
function (config) {
18+
const rule = new Rule(config);
19+
rule.useStylus();
20+
}
21+
)(config);
22+
};
23+

0 commit comments

Comments
 (0)