add Element-Ui using cdn tutorial

This commit is contained in:
Pan
2018-05-14 10:48:27 +08:00
parent f01a1ad7b7
commit d47939e4e6
2 changed files with 50 additions and 0 deletions

View File

@@ -46,6 +46,29 @@ npm run build --report
## Demo
![demo](https://github.com/PanJiaChen/PanJiaChen.github.io/blob/master/images/demo.gif)
## Element-Ui 使用cdn教程
首先找到 `index.html` ([根目录下](https://github.com/PanJiaChen/vueAdmin-template/blob/element-ui-cdn/index.html))
引入 Element的css和js ,并且引入 vue 。因为 Element-Ui 是依赖 vue 的,所以必须在它之前引入 vue 。
之后找到 [webpack.base.conf.js](https://github.com/PanJiaChen/vueAdmin-template/blob/element-ui-cdn/build/webpack.base.conf.js) 加入 `externals` 让webpack 不打包 vue 和 element
```
externals: {
vue: 'Vue',
'element-ui':'ELEMENT'
}
```
之后还有一个小细节是如果你用了全局对象方式引入vue就不需要 手动 `Vue.use(Vuex` ,它会自动挂载,具体见 [issue](https://github.com/vuejs/vuex/issues/731)
最终你可以使用 `npm run build --report` 查看效果
如图:
![demo](https://panjiachen.github.io/images/element-cdn.png)
**[具体代码](https://github.com/PanJiaChen/vueAdmin-template/commit/746aff560932704ae821f82f10b8b2a9681d5177)**
**[对应分支](https://github.com/PanJiaChen/vueAdmin-template/tree/element-ui-cdn)
## License
[MIT](https://github.com/PanJiaChen/vueAdmin-template/blob/master/LICENSE) license.