Skip to content

Commit 55da493

Browse files
author
why
committed
first commit
0 parents  commit 55da493

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+37425
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"@babel/env"
4+
]
5+
}

.browserslistrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
> 1%
2+
last 2 versions
3+
not dead

.componentrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Asd","className":"asd","version":"1.0.0","description":"asd","buildPath":"dist","examplePath":"examples","npmName":"@imooc-cli/vue3-component","npmVersion":"1.0.0"}

.eslintrc.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module.exports = {
2+
root: true,
3+
4+
env: {
5+
node: true
6+
},
7+
8+
'extends': [
9+
'plugin:vue/vue3-essential',
10+
'eslint:recommended',
11+
'@vue/typescript/recommended'
12+
],
13+
14+
parserOptions: {
15+
ecmaVersion: 2020
16+
},
17+
18+
rules: {
19+
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
20+
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
21+
},
22+
23+
overrides: [
24+
{
25+
files: [
26+
'**/__tests__/*.{j,t}s?(x)',
27+
'**/tests/unit/**/*.spec.{j,t}s?(x)'
28+
],
29+
env: {
30+
jest: true
31+
}
32+
}
33+
]
34+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

NPMPulish.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# npm publish
2+
## npm login登陆
3+
## package.json配置
4+
* "private": false
5+
* "files": ["dist"] // 发布的时候上传哪些文件
6+
* "peerDependencies": {"vue": "^3.0.0"} // 外部依赖
7+
* script: { "prepublishOnly": "npm run build" } // 确保npm publish的是最新的dist文件
8+
9+
## 发布前的准备
10+
* 检查eslint---npm run lint
11+
* 单元测试---npm run test
12+
* rollup打包---npm run build
13+
14+
## 安装husky运行git生命周期
15+
```
16+
npm install husky@4 -D
17+
18+
// package.json 配置下面这段代码
19+
"husky": {
20+
"hooks": {
21+
"pre-commit": "npm run lint && npm run test"
22+
}
23+
}
24+
```

README.md

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# rollpu 打包组件库
2+
* 每一个组件实例上挂载install方法
3+
这是为了能够使用
4+
import {LText} from 'abb-component'
5+
app.use(LText)
6+
这种方式单独引入组件
7+
```
8+
import { App } from 'vue'
9+
import LShape from './LShape.vue'
10+
LShape.install = (app: App) => {
11+
app.component(LShape.name, LShape)
12+
}
13+
14+
export default LShape
15+
```
16+
* 配置入口文件index.ts
17+
这是为了能够使用
18+
import AbbComponent from 'abb-component'
19+
app.use(AbbComponent)
20+
这种方式引入全部组件
21+
```
22+
import {App} from 'vue';
23+
import LText from './components/LText';
24+
import LImage from './components/LImage';
25+
import LShape from './components/LShape';
26+
27+
const components = [
28+
LText,
29+
LImage,
30+
LShape
31+
]
32+
33+
const install = (app: App) => {
34+
components.forEach(component => {
35+
app.component(component.name, component)
36+
})
37+
}
38+
39+
export {
40+
LText,
41+
LImage,
42+
LShape,
43+
install
44+
}
45+
46+
export default {
47+
install
48+
}
49+
```
50+
* 配置rollup.config.js文件
51+
依赖的插件
52+
+ @rollup/plugin-json //解析模块中导入*.json文件
53+
+ @rollup/plugin-node-resolve //解析node_modules中绝对路径的引入
54+
+ rollup-plugin-css-only //解析*.vue文件中<style></style>中的内容
55+
+ rollup-plugin-typescript2 //解析*.ts文件
56+
+ rollup-plugin-vue //解析*.vue文件
57+
* tsconfig配置导出*.d.ts文件
58+
```
59+
compilerOptions: {
60+
declaration: true
61+
}
62+
```
63+
* 配置package.json文件中的第三方依赖
64+
如果npm install abb-components 的时候发现项目中并没有安装vue包,就会打印warning信息
65+
```
66+
"peerDependencies": {
67+
"vue": "^3.0.0"
68+
}
69+
```
70+
* rollup.config.json文件中的第三方依赖
71+
打包生成的文件中并没有将引用到的vue, loadsh-es这两个库中的代码融合,而是通过import {} from '' 这种方式饮用,所以想用这个组件库,就必须在项目中安装vue, loadsh-es
72+
```
73+
external: ['vue', 'loadsh-es']
74+
```
75+
76+
* 拆分打包配置文件
77+
对于umd格式的文件需要做单独处理
78+
因为在上一步配置了外部依赖库,所以在倒入的时候需要知道这个外部依赖库的全局变量名
79+
还需要配置这个组件库的全局变量名
80+
```
81+
output: {
82+
name: 'ABBComponent',
83+
file: file('umd'),
84+
format: 'umd',
85+
globals: {
86+
'vue': 'Vue',
87+
'loadsh-es': '_'
88+
},
89+
exports: 'named'
90+
}
91+
```
92+
93+
* package.json文件内配置
94+
当一个项目安装了这个组件库, 那么就会在import from的时候去找到这个组件库的入口文件
95+
但如果项目使用的是es模块,且组件库package.json配置了module这个属性,那么就会优先引用这个配置的文件
96+
```
97+
"main": "dist/app-component.umd.js",
98+
"module": "dist/app-component.esm.js",
99+
"types": "dist/index.d.ts"
100+
101+
```
102+

babel.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@vue/cli-plugin-babel/preset'
4+
]
5+
}

dist/abb-component.esm.js

+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
import { computed, defineComponent, openBlock, createBlock, resolveDynamicComponent, normalizeStyle, withCtx, createTextVNode, toDisplayString, pushScopeId, popScopeId, createElementBlock, withModifiers } from 'vue';
2+
import { without, mapValues, pick } from 'lodash-es';
3+
4+
const commonDefaultProps = {
5+
// actions
6+
actionType: '',
7+
url: '',
8+
// size
9+
height: '',
10+
width: '373px',
11+
paddingLeft: '0px',
12+
paddingRight: '0px',
13+
paddingTop: '0px',
14+
paddingBottom: '0px',
15+
// border type
16+
borderStyle: 'none',
17+
borderColor: '#000',
18+
borderWidth: '0',
19+
borderRadius: '0',
20+
// shadow and opacity
21+
boxShadow: '0 0 0 #000000',
22+
opacity: '1',
23+
// position and x,y
24+
position: 'absolute',
25+
left: '0',
26+
top: '0',
27+
right: '0'
28+
};
29+
const textDefaultProps = {
30+
// basic props - font styles
31+
text: '正文内容',
32+
fontSize: '14px',
33+
fontFamily: '',
34+
fontWeight: 'normal',
35+
fontStyle: 'normal',
36+
textDecoration: 'none',
37+
lineHeight: '1',
38+
textAlign: 'left',
39+
color: '#000000',
40+
backgroundColor: '',
41+
...commonDefaultProps
42+
};
43+
const imageDefaultProps = {
44+
src: 'test.url',
45+
...commonDefaultProps
46+
};
47+
const shapeDefaultProps = {
48+
backgroundColor: '',
49+
...commonDefaultProps
50+
};
51+
const isEditingProp = {
52+
isEditing: {
53+
type: Boolean,
54+
default: false
55+
}
56+
};
57+
const textStylePropNames = without(Object.keys(textDefaultProps), 'actionType', 'url', 'text');
58+
const imageStylePropsNames = without(Object.keys(imageDefaultProps), 'actionType', 'url', 'src');
59+
const shapeStylePropsNames = without(Object.keys(imageDefaultProps), 'actionType', 'url');
60+
const transformToComponentProps = (props) => {
61+
const mapProps = mapValues(props, (item) => {
62+
return {
63+
type: item.constructor,
64+
default: item
65+
};
66+
});
67+
return { ...mapProps, ...isEditingProp };
68+
};
69+
70+
const useComponentCommon = (props, picks) => {
71+
const styleProps = computed(() => pick(props, picks));
72+
const handleClick = () => {
73+
if (props.actionType === 'url' && props.url && !props.isEditing) {
74+
window.location.href = props.url;
75+
}
76+
};
77+
return {
78+
styleProps,
79+
handleClick,
80+
};
81+
};
82+
83+
const defaultProps$2 = transformToComponentProps(textDefaultProps);
84+
var script$2 = defineComponent({
85+
name: 'LText',
86+
props: {
87+
...defaultProps$2,
88+
tag: {
89+
type: String,
90+
default: 'div',
91+
},
92+
},
93+
setup(props) {
94+
const { styleProps, handleClick } = useComponentCommon(props, textStylePropNames);
95+
return {
96+
styleProps,
97+
handleClick,
98+
};
99+
},
100+
});
101+
102+
function render$2(_ctx, _cache, $props, $setup, $data, $options) {
103+
return (openBlock(), createBlock(resolveDynamicComponent(_ctx.tag), {
104+
style: normalizeStyle(_ctx.styleProps),
105+
class: "l-text-component",
106+
onClick: _ctx.handleClick
107+
}, {
108+
default: withCtx(() => [
109+
createTextVNode(toDisplayString(_ctx.text), 1 /* TEXT */)
110+
]),
111+
_: 1 /* STABLE */
112+
}, 8 /* PROPS */, ["style", "onClick"]))
113+
}
114+
115+
script$2.render = render$2;
116+
script$2.__scopeId = "data-v-6bf95b7a";
117+
script$2.__file = "src/components/LText/LText.vue";
118+
119+
script$2.install = (app) => {
120+
app.component(script$2.name, script$2);
121+
};
122+
123+
const defaultProps$1 = transformToComponentProps(imageDefaultProps);
124+
// array that contains style props
125+
var script$1 = defineComponent({
126+
name: 'l-image',
127+
props: {
128+
...defaultProps$1
129+
},
130+
setup(props) {
131+
// 重用并且简化
132+
// 抽离并且获得 styleProps
133+
const { styleProps, handleClick } = useComponentCommon(props, imageStylePropsNames);
134+
return {
135+
styleProps,
136+
handleClick
137+
};
138+
}
139+
});
140+
141+
pushScopeId("data-v-1e970aa2");
142+
const _hoisted_1 = ["src"];
143+
popScopeId();
144+
145+
function render$1(_ctx, _cache, $props, $setup, $data, $options) {
146+
return (openBlock(), createElementBlock("img", {
147+
style: normalizeStyle(_ctx.styleProps),
148+
class: "l-image-component",
149+
onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
150+
src: _ctx.src
151+
}, null, 12 /* STYLE, PROPS */, _hoisted_1))
152+
}
153+
154+
script$1.render = render$1;
155+
script$1.__scopeId = "data-v-1e970aa2";
156+
script$1.__file = "src/components/LImage/LImage.vue";
157+
158+
script$1.install = (app) => {
159+
app.component(script$1.name, script$1);
160+
};
161+
162+
const defaultProps = transformToComponentProps(shapeDefaultProps);
163+
// array that contains style props
164+
var script = defineComponent({
165+
name: 'l-shape',
166+
props: {
167+
...defaultProps
168+
},
169+
setup(props) {
170+
// 重用并且简化
171+
// 抽离并且获得 styleProps
172+
const { styleProps, handleClick } = useComponentCommon(props, shapeStylePropsNames);
173+
return {
174+
styleProps,
175+
handleClick
176+
};
177+
}
178+
});
179+
180+
function render(_ctx, _cache, $props, $setup, $data, $options) {
181+
return (openBlock(), createElementBlock("div", {
182+
style: normalizeStyle(_ctx.styleProps),
183+
class: "l-shape-component",
184+
onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
185+
}, null, 4 /* STYLE */))
186+
}
187+
188+
script.render = render;
189+
script.__file = "src/components/LShape/LShape.vue";
190+
191+
script.install = (app) => {
192+
app.component(script.name, script);
193+
};
194+
195+
const components = [
196+
script$2,
197+
script$1,
198+
script
199+
];
200+
const install = (app) => {
201+
components.forEach(component => {
202+
app.component(component.name, component);
203+
});
204+
};
205+
var index = {
206+
install
207+
};
208+
209+
export { script$1 as LImage, script as LShape, script$2 as LText, index as default, install };

0 commit comments

Comments
 (0)