Skip to content

Commit 55ce0dc

Browse files
committed
fix quick-start post-compile
1 parent cfcd50e commit 55ce0dc

File tree

1 file changed

+103
-25
lines changed

1 file changed

+103
-25
lines changed

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

Lines changed: 103 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,39 @@ $ npm install cube-ui --save
1212

1313
但在使用之前,需要配置下这个插件,修改 .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+
如果不使用 babel-plugin-transform-modules 插件的话,需要手工引入对应的样式文件:
28+
29+
```js
30+
import 'cube-ui/lib/style.css'
31+
```
3832

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

41-
如果不使用 babel-plugin-transform-modules 插件的话,需要手工引入对应的样式文件。
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
#### 全部引入
4450

@@ -112,3 +118,75 @@ import {
112118
}
113119
</script>
114120
```
121+
122+
### 使用后编译
123+
124+
cube-ui 搭配 webpack 2+ 后就会默认走[后编译](#/zh-CN/docs/post-compile),那么应用就需要兼容 cube-ui 的依赖和配置。
125+
126+
1. 修改 package.json
127+
128+
```json
129+
{
130+
// webpack-post-compile-plugin 使用 compileDependencies
131+
"compileDependencies": ["cube-ui"],
132+
"devDependencies": {
133+
// 新增 stylus 相关依赖
134+
"stylus": "^0.54.5",
135+
"stylus-loader": "^2.1.1",
136+
"webpack-post-compile-plugin": "^0.1.2"
137+
}
138+
}
139+
```
140+
版本无强制要求。
141+
142+
2. 修改 .babelrc:
143+
144+
```json
145+
{
146+
"plugins": ["transform-modules", {
147+
"cube-ui": {
148+
"transform": "cube-ui/src/modules/${member}",
149+
"kebabCase": true
150+
}
151+
}]
152+
}
153+
```
154+
155+
3. 修改 webpack.base.conf.js
156+
157+
```js
158+
var PostCompilePlugin = require('webpack-post-compile-plugin')
159+
module.exports = {
160+
// ...
161+
plugins: [
162+
// ...
163+
new PostCompilePlugin()
164+
]
165+
// ...
166+
}
167+
```
168+
169+
4. 修改 build/utils.js 中的 exports.cssLoaders 函数
170+
171+
```js
172+
173+
```
174+
exports.cssLoaders = function (options) {
175+
// ...
176+
const stylusOptions = {
177+
'resolve url': true
178+
}
179+
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
180+
return {
181+
css: generateLoaders(),
182+
postcss: generateLoaders(),
183+
less: generateLoaders('less'),
184+
sass: generateLoaders('sass', { indentedSyntax: true }),
185+
scss: generateLoaders('sass'),
186+
stylus: generateLoaders('stylus', stylusOptions),
187+
styl: generateLoaders('stylus', stylusOptions)
188+
}
189+
}
190+
```
191+
192+
具体参见 https://github.com/vuejs-templates/webpack/pull/970/files

0 commit comments

Comments
 (0)