Skip to content

Commit b965d89

Browse files
Jackyzmtangjinzhou
authored andcommitted
docs: update to vue-cli3 (#304)
1 parent 68ca7b9 commit b965d89

File tree

2 files changed

+57
-27
lines changed

2 files changed

+57
-27
lines changed

docs/vue/use-with-vue-cli.en-US.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
21
# Use in vue-cli 3
32

43
[vue-cli](https://github.com/vuejs/vue-cli) is one of the best Vue application development tools. We are going to use `antd` within it and modify the webpack config for some customized needs.
54

6-
75
## Install and Initialization
86

97
We need to install `vue-cli` first, you may need install [yarn](https://github.com/yarnpkg/yarn/) too.
@@ -64,22 +62,23 @@ $ yarn add ant-design-vue
6462
Modify `src/main.js`, import Button component from `antd`.
6563

6664
```jsx
67-
import Vue from 'vue'
68-
import Button from 'ant-design-vue/lib/button'
69-
import 'ant-design-vue/dist/antd.css'
70-
import App from './App'
65+
import Vue from "vue";
66+
import Button from "ant-design-vue/lib/button";
67+
import "ant-design-vue/dist/antd.css";
68+
import App from "./App";
7169

72-
Vue.component(Button.name, Button)
70+
Vue.component(Button.name, Button);
7371

74-
Vue.config.productionTip = false
72+
Vue.config.productionTip = false;
7573

7674
/* eslint-disable no-new */
7775
new Vue({
78-
el: '#app',
76+
el: "#app",
7977
components: { App },
80-
template: '<App/>'
81-
})
78+
template: "<App/>"
79+
});
8280
```
81+
8382
Modify `src/App.vue`
8483

8584
```jsx
@@ -93,10 +92,8 @@ Modify `src/App.vue`。
9392
...
9493
```
9594

96-
9795
Ok, you should now see a blue primary button displayed on the page. Next you can choose any components of `antd` to develop your application. Visit other workflows of `vue-cli` at its [User Guide ](https://github.com/vuejs/vue-cli/blob/master/README.md).
9896

99-
10097
## Advanced Guides
10198

10299
We are successfully running antd components now but in the real world, there are still lots of problems about antd-demo.
@@ -112,6 +109,8 @@ Now we need to customize the default webpack config.
112109
$ yarn add babel-plugin-import --dev
113110
```
114111

112+
#### if you use vue-cli 2
113+
115114
Modify `.babelrc`.
116115

117116
```diff
@@ -134,6 +133,22 @@ Modify `.babelrc`.
134133
}
135134
```
136135

136+
#### if you use vue-cli 3
137+
138+
Modify `babel.config.js`
139+
140+
```diff
141+
module.exports = {
142+
presets: ["@vue/app"],
143+
+ plugins: [
144+
+ [
145+
+ "import",
146+
+ { libraryName: "ant-design-vue", libraryDirectory: "es", style: true }
147+
+ ]
148+
+ ]
149+
};
150+
```
151+
137152
Remove the `import 'ant-design-vue/dist/antd.css';` statement added before because `babel-plugin-import` will import styles and import components like below:
138153

139154
```diff

docs/vue/use-with-vue-cli.zh-CN.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
21
# 在 vue-cli 3 中使用
32

43
[vue-cli](https://github.com/vuejs/vue-cli) 是业界最优秀的 Vue 应用开发工具之一,本文会尝试在 vue-cli 创建的工程中使用 antd 组件,并自定义 webpack 的配置以满足各类工程化需求。
54

6-
75
## 安装和初始化
86

97
我们需要在命令行中安装 vue-cli 工具,你可能还需要安装 [yarn](https://github.com/yarnpkg/yarn/)
@@ -63,23 +61,24 @@ $ yarn add ant-design-vue
6361
修改 `src/main.js`,引入 antd 的按钮组件以及全部样式文件。
6462

6563
```jsx
66-
import Vue from 'vue'
67-
import Button from 'ant-design-vue/lib/button'
68-
import 'ant-design-vue/dist/antd.css'
69-
import App from './App'
64+
import Vue from "vue";
65+
import Button from "ant-design-vue/lib/button";
66+
import "ant-design-vue/dist/antd.css";
67+
import App from "./App";
7068

71-
Vue.component(Button.name, Button)
69+
Vue.component(Button.name, Button);
7270

73-
Vue.config.productionTip = false
71+
Vue.config.productionTip = false;
7472

7573
/* eslint-disable no-new */
7674
new Vue({
77-
el: '#app',
75+
el: "#app",
7876
components: { App },
79-
template: '<App/>'
80-
})
77+
template: "<App/>"
78+
});
8179
```
82-
修改 `src/App.vue`的template内容。
80+
81+
修改 `src/App.vue`的 template 内容。
8382

8483
```jsx
8584
<template>
@@ -108,7 +107,9 @@ new Vue({
108107
$ yarn add babel-plugin-import --dev
109108
```
110109

111-
修改`.babelrc`文件,配置babel-plugin-import
110+
#### 使用 vue-cli 2 的小伙伴
111+
112+
修改`.babelrc`文件,配置 babel-plugin-import
112113

113114
```diff
114115
{
@@ -130,6 +131,21 @@ $ yarn add babel-plugin-import --dev
130131
}
131132
```
132133

134+
#### 使用 vue-cli 3 的小伙伴
135+
136+
修改`babel.config.js`文件,配置 babel-plugin-import
137+
138+
```diff
139+
module.exports = {
140+
presets: ["@vue/app"],
141+
+ plugins: [
142+
+ [
143+
+ "import",
144+
+ { libraryName: "ant-design-vue", libraryDirectory: "es", style: true }
145+
+ ]
146+
+ ]
147+
};
148+
```
133149

134150
然后移除前面在 `src/main.js` 里全量添加的 `import 'ant-design-vue/dist/antd.css';` 样式代码,并且按下面的格式引入模块。
135151

@@ -158,4 +174,3 @@ $ yarn add babel-plugin-import --dev
158174
### 自定义主题
159175

160176
按照 [配置主题](/ant-design-vue/docs/vue/customize-theme-cn) 的要求,自定义主题需要用到 less 变量覆盖功能。
161-

0 commit comments

Comments
 (0)