Skip to content

Commit 9bafbf9

Browse files
committed
finish quick-start doc
1 parent 55ce0dc commit 9bafbf9

File tree

2 files changed

+116
-39
lines changed

2 files changed

+116
-39
lines changed

document/components/docs/en-US/quick-start.md

Lines changed: 103 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,39 @@ It is recommended to use [babel-plugin-transform-modules](https://www.npmjs.com/
1212

1313
Before use, the plugin needs some configuration. Modify .babelrc:
1414

15-
- webpack 1.x
16-
```json
17-
{
18-
"plugins": ["transform-modules", {
19-
"cube-ui": {
20-
"transform": "cube-ui/lib/${member}",
21-
"kebabCase": true,
22-
"style": true
23-
}
24-
}]
25-
}
26-
```
27-
- webpack 2+
28-
```json
29-
{
30-
"plugins": ["transform-modules", {
31-
"cube-ui": {
32-
"transform": "cube-ui/src/modules/${member}",
33-
"kebabCase": true
34-
}
35-
}]
36-
}
37-
```
15+
```json
16+
{
17+
"plugins": ["transform-modules", {
18+
"cube-ui": {
19+
"transform": "cube-ui/lib/${member}",
20+
"kebabCase": true,
21+
"style": true
22+
}
23+
}]
24+
}
25+
```
26+
27+
If not using babel-plugin-transform-modules, you need to import corresponding style files by hand:
28+
29+
```js
30+
import 'cube-ui/lib/style.css'
31+
```
3832

39-
> [why distinguishs the version of webpack?](#/en-US/docs/post-compile)
33+
**Notice:** By default cube-ui will use [post-compile](#/en-US/docs/post-compile) with webpack 2+, but post-complie needs some dependencies and configuration. If you don't want to use post-compile, just modify the webpack config file:
4034

41-
If not using babel-plugin-transform-modules, you need to import corresponding style files by hand.
35+
```js
36+
// webpack.config.js
37+
38+
module.exports = {
39+
// ...
40+
resolve: {
41+
// ...
42+
// https://webpack.js.org/configuration/resolve/#resolve-mainfields
43+
mainFields: ["main"]
44+
}
45+
// ...
46+
}
47+
```
4248

4349
#### Fully import
4450

@@ -111,3 +117,75 @@ import {
111117
}
112118
</script>
113119
```
120+
121+
122+
### Use post-compile
123+
124+
Since cube-ui will use [post-compile](#/en-US/docs/post-compile) with webpack 2+ by default, your application's webpack and babel configuration needs to be compatible with cube-ui.
125+
126+
Follow the steps below:
127+
128+
1. Modify package.json
129+
130+
```json
131+
{
132+
// webpack-post-compile-plugin depends on compileDependencies
133+
"compileDependencies": ["cube-ui"],
134+
"devDependencies": {
135+
// add stylus dependencies
136+
"stylus": "^0.54.5",
137+
"stylus-loader": "^2.1.1",
138+
"webpack-post-compile-plugin": "^0.1.2"
139+
}
140+
}
141+
```
142+
143+
2. Modify .babelrc:
144+
145+
```json
146+
{
147+
"plugins": ["transform-modules", {
148+
"cube-ui": {
149+
"transform": "cube-ui/src/modules/${member}",
150+
"kebabCase": true
151+
}
152+
}]
153+
}
154+
```
155+
156+
3. Modify webpack.base.conf.js
157+
158+
```js
159+
var PostCompilePlugin = require('webpack-post-compile-plugin')
160+
module.exports = {
161+
// ...
162+
plugins: [
163+
// ...
164+
new PostCompilePlugin()
165+
]
166+
// ...
167+
}
168+
```
169+
170+
4. Modify `exports.cssLoaders` function in build/utils.js
171+
172+
```js
173+
exports.cssLoaders = function (options) {
174+
// ...
175+
const stylusOptions = {
176+
'resolve url': true
177+
}
178+
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
179+
return {
180+
css: generateLoaders(),
181+
postcss: generateLoaders(),
182+
less: generateLoaders('less'),
183+
sass: generateLoaders('sass', { indentedSyntax: true }),
184+
scss: generateLoaders('sass'),
185+
stylus: generateLoaders('stylus', stylusOptions),
186+
styl: generateLoaders('stylus', stylusOptions)
187+
}
188+
}
189+
```
190+
191+
See [https://github.com/vuejs-templates/webpack/pull/970/files](https://github.com/vuejs-templates/webpack/pull/970/files)

document/components/docs/zh-CN/quick-start.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $ npm install cube-ui --save
3030
import 'cube-ui/lib/style.css'
3131
```
3232

33-
**注意:** cube-ui 搭配 webpack 2+ 默认就会走[后编译](#/zh-CN/docs/post-compile),但是后编译需要有一些依赖以及配置(参见本页最后);如果不想使用后编译的话,可以直接修改 webpack 配置即可:
33+
**注意:** cube-ui 搭配 webpack 2+ 默认就会使用[后编译](#/zh-CN/docs/post-compile),但是后编译需要有一些依赖以及配置(参见本页最后);如果不想使用后编译的话,可以直接修改 webpack 配置即可:
3434

3535
```js
3636
// webpack.config.js
@@ -121,13 +121,13 @@ import {
121121

122122
### 使用后编译
123123

124-
cube-ui 搭配 webpack 2+ 后就会默认走[后编译](#/zh-CN/docs/post-compile),那么应用就需要兼容 cube-ui 的依赖和配置。
124+
cube-ui 搭配 webpack 2+ 后就会默认使用[后编译](#/zh-CN/docs/post-compile),那么应用就需要兼容 cube-ui 的依赖和配置。
125125

126126
1. 修改 package.json
127127

128128
```json
129129
{
130-
// webpack-post-compile-plugin 使用 compileDependencies
130+
// webpack-post-compile-plugin 依赖 compileDependencies
131131
"compileDependencies": ["cube-ui"],
132132
"devDependencies": {
133133
// 新增 stylus 相关依赖
@@ -137,18 +137,19 @@ cube-ui 搭配 webpack 2+ 后就会默认走[后编译](#/zh-CN/docs/post-compil
137137
}
138138
}
139139
```
140-
版本无强制要求。
141140

142141
2. 修改 .babelrc:
143142

144143
```json
145144
{
146-
"plugins": ["transform-modules", {
147-
"cube-ui": {
148-
"transform": "cube-ui/src/modules/${member}",
149-
"kebabCase": true
150-
}
151-
}]
145+
"plugins": [
146+
["transform-modules", {
147+
"cube-ui": {
148+
"transform": "cube-ui/src/modules/${member}",
149+
"kebabCase": true
150+
}
151+
}]
152+
]
152153
}
153154
```
154155

@@ -166,11 +167,9 @@ cube-ui 搭配 webpack 2+ 后就会默认走[后编译](#/zh-CN/docs/post-compil
166167
}
167168
```
168169

169-
4. 修改 build/utils.js 中的 exports.cssLoaders 函数
170+
4. 修改 build/utils.js 中的 `exports.cssLoaders` 函数
170171

171172
```js
172-
173-
```
174173
exports.cssLoaders = function (options) {
175174
// ...
176175
const stylusOptions = {
@@ -189,4 +188,4 @@ cube-ui 搭配 webpack 2+ 后就会默认走[后编译](#/zh-CN/docs/post-compil
189188
}
190189
```
191190

192-
具体参见 https://github.com/vuejs-templates/webpack/pull/970/files
191+
具体参见 [https://github.com/vuejs-templates/webpack/pull/970/files](https://github.com/vuejs-templates/webpack/pull/970/files)

0 commit comments

Comments
 (0)