File tree Expand file tree Collapse file tree 4 files changed +43
-13069
lines changed Expand file tree Collapse file tree 4 files changed +43
-13069
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,40 @@ npm run build
8181# https://cli.vuejs.org/guide/troubleshooting.html#symbolic-links-in-node-modules
8282```
8383
84+ ## 依赖方如何安装组件库?
85+
86+ ### 全量导入
87+
88+ ``` js
89+ // components 为你的组件库名称
90+ // style 为你的 CSS 文件名
91+ import components from ' components' ;
92+ import ' components/cjs/style.css' ;
93+ ```
94+
95+ ### 按需加载
96+
97+ 首先在依赖方的项目中安装以下依赖。
98+
99+ ``` bash
100+ npm i babel-plugin-component -D
101+ ```
102+
103+ 然后在 babel 配置文件中加入以下代码,` components ` 为你的组件库名称。
104+
105+ ``` json
106+ {
107+ "plugins" : [[" component" , { "libraryName" : " components" }]]
108+ }
109+ ```
110+
111+ 然后在你的文件中这样导入即可。
112+
113+ ``` js
114+ // components 为你的组件库名称
115+ import { Button } from ' components' ;
116+ ```
117+
84118## 关于 ESLint 规范
85119
86120本项目使用 [ eslint-config-team-spec] ( https://github.com/Yingkaixiang/eslint-config-team-spec ) 作为 ` ESLint ` 规范。此规范是笔者基于 [ eslint-config-alloy] ( https://github.com/AlloyTeam/eslint-config-alloy ) 的规范整理出的自己团队的编码规范。如果你不想使用我的规则,可以自行替换为你的规则。
Original file line number Diff line number Diff line change @@ -8,14 +8,14 @@ const webpackBaseConfig = require('./webpack.base');
88module . exports = merge ( webpackBaseConfig , {
99 entry : getEntries ( ) ,
1010 output : {
11- path : resolve ( " ../lib" ) ,
12- filename : " [name]/index .js" ,
11+ path : resolve ( ' ../lib' ) ,
12+ filename : ' [name].js' ,
1313 libraryExport : 'default' ,
14- libraryTarget : " commonjs2" ,
14+ libraryTarget : ' commonjs2' ,
1515 } ,
1616 plugins : [
1717 new MiniCssExtractPlugin ( {
18- filename : " [name]/style.css" ,
18+ filename : ' [name]/style.css' ,
1919 } ) ,
2020 ] ,
21- } ) ;
21+ } ) ;
Original file line number Diff line number Diff line change 11import Button from '../components/button/' ;
22
3+ // 组件库导入
34const components = [ Button ] ;
45
56const install = function ( Vue ) {
@@ -14,3 +15,6 @@ export default {
1415 install,
1516 Button,
1617} ;
18+
19+ // 单个组件可以直接这样导出
20+ // export default Button;
You can’t perform that action at this time.
0 commit comments