@darkchest/wck 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkchest/wck",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "@darkchest/wck
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "@darkchest/wck是一个通过将 Vue 单文件组件 (SFC) 转换为通用的web-component组件的解决方案。",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"type": "module",
|
package/readme.md
CHANGED
|
@@ -40,10 +40,11 @@
|
|
|
40
40
|
由于vue中定义props是允许大小写字母的.而web组件只允许小写字母(包含中划线), 所以当我们在vue组件中定义一个带有大写字母的属性时(例如appTitle), 那么我们将它转成web组件后, 插件会在web组件中将appTitle声明为apptitle和app-title两种形式, 所以这俩种写法最后都有效: <todo-list apptitle="*我的清单*"></todo-list>和<todo-list app-title="*我的清单*"></todo-list>.
|
|
41
41
|
|
|
42
42
|
### 关于属性, 方法, 事件, 生命周期钩子
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
- 在vue组件中props和methods定义的属性和方法, 都会直接通过web组件暴露给页面.
|
|
44
|
+
- 在vue组件中支持(onMounted/mounted)和(onUnmounted/destroyed)生命周期钩子函数来执行初始化与销毁操作.
|
|
45
|
+
- 所有编译后的web组件都会默认触发mounted/unmounted两个生命周期事件方便页面监听并进行某些初始化操作.
|
|
46
|
+
- 所有编译后的web组件都默认增加$el, $parent, $children, $root属性.
|
|
47
|
+
- 所有编译后的web组件都默认增加$emit(name, data), on(name, handler), off(name, handler), off(name, handler)方法.
|
|
47
48
|
|
|
48
49
|
## 🛠️ 安装与配置
|
|
49
50
|
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
npm install @darkchest/wck
|
|
54
55
|
```
|
|
55
56
|
|
|
56
|
-
### 2. 使用示例(重要: 请参考TodoList.vue文件示例,
|
|
57
|
+
### 2. 使用示例(重要: 请参考TodoList.vue文件示例, 该文件中已包含所有核心功能并且开箱即用)
|
|
57
58
|
```javascript
|
|
58
59
|
// vite.config.js
|
|
59
60
|
import { defineConfig } from 'vite';
|
package/src/compiler-template.js
CHANGED
|
@@ -19,26 +19,6 @@ export const compileExportDefault = (ast) => {
|
|
|
19
19
|
|
|
20
20
|
const isSimpleType = (node) => t.isIdentifier(node) && ['String', 'Number', 'Boolean'].includes(node.name);
|
|
21
21
|
|
|
22
|
-
const getFunctionAst = (node) => parser.parse('const fn = ' + generate(node)?.code, { sourceType: 'module' });
|
|
23
|
-
|
|
24
|
-
const getFunctionReturnValue = (node) => {
|
|
25
|
-
const returnStatements = [];
|
|
26
|
-
const ast = getFunctionAst(node);
|
|
27
|
-
traverse.default(ast, {
|
|
28
|
-
ReturnStatement(path) {
|
|
29
|
-
returnStatements.push(path.node.argument);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
const returnNode = returnStatements?.[0];
|
|
33
|
-
if (returnNode && t.isArrayExpression(returnNode)) {
|
|
34
|
-
return eval(generate(returnNode)?.code);
|
|
35
|
-
}
|
|
36
|
-
if (returnNode && t.isObjectExpression(returnNode)) {
|
|
37
|
-
return eval(`(${generate(returnNode)?.code})`);
|
|
38
|
-
}
|
|
39
|
-
return undefined;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
22
|
const getFunctionCode = (node) => {
|
|
43
23
|
let async = false;
|
|
44
24
|
let paramsNode = [];
|