@wevu/compiler 0.0.1 → 0.0.3
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/README.md +68 -0
- package/dist/index.mjs +5 -0
- package/package.json +6 -6
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @wevu/compiler
|
|
2
|
+
|
|
3
|
+
## 简介
|
|
4
|
+
|
|
5
|
+
`@wevu/compiler` 提供 Wevu 的编译能力,面向小程序模板与 Vue SFC 的解析、转换与输出。它从 weapp-vite 中抽离出纯编译管线,供 `wevu/compiler` 与 weapp-vite 等上层工具复用。
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- Vue SFC 编译(script/template/style/config)
|
|
10
|
+
- WXML/WXSS 编译与多平台模板适配
|
|
11
|
+
- JSON 配置解析与合并策略
|
|
12
|
+
- Wevu 页面特性分析与注入
|
|
13
|
+
- 可作为独立编译器在非 Vite 场景使用
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @wevu/compiler
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 使用
|
|
22
|
+
|
|
23
|
+
编译单个 Vue SFC:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { compileSfc } from '@wevu/compiler'
|
|
27
|
+
|
|
28
|
+
const result = await compileSfc(
|
|
29
|
+
sourceCode,
|
|
30
|
+
filename,
|
|
31
|
+
{
|
|
32
|
+
isPage: true,
|
|
33
|
+
template: { /* 模板编译参数 */ },
|
|
34
|
+
json: { kind: 'page' },
|
|
35
|
+
},
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
console.log(result.script)
|
|
39
|
+
console.log(result.template)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
使用页面特性工具:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import {
|
|
46
|
+
collectWevuPageFeatureFlags,
|
|
47
|
+
injectWevuPageFeaturesInJs,
|
|
48
|
+
} from '@wevu/compiler'
|
|
49
|
+
|
|
50
|
+
const flags = collectWevuPageFeatureFlags(sourceCode)
|
|
51
|
+
const nextCode = injectWevuPageFeaturesInJs(sourceCode, flags)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 配置
|
|
55
|
+
|
|
56
|
+
`compileSfc`(`compileVueFile`)常用选项:
|
|
57
|
+
|
|
58
|
+
- `isPage` / `isApp`
|
|
59
|
+
- `warn`:自定义警告输出
|
|
60
|
+
- `template`:模板编译参数
|
|
61
|
+
- `json`:配置合并策略
|
|
62
|
+
- `autoUsingComponents` / `autoImportTags`
|
|
63
|
+
- `wevuDefaults`:Wevu 默认配置
|
|
64
|
+
|
|
65
|
+
## 相关链接
|
|
66
|
+
|
|
67
|
+
- weapp-vite 文档:https://vite.icebreaker.top/
|
|
68
|
+
- 仓库:https://github.com/weapp-vite/weapp-vite
|
package/dist/index.mjs
CHANGED
|
@@ -4174,6 +4174,10 @@ function vueSfcTransformPlugin() {
|
|
|
4174
4174
|
function isDefineComponentCall(node, aliases) {
|
|
4175
4175
|
return t.isIdentifier(node.callee) && aliases.has(node.callee.name);
|
|
4176
4176
|
}
|
|
4177
|
+
function isObjectAssignCall(node) {
|
|
4178
|
+
const callee = node.callee;
|
|
4179
|
+
return t.isMemberExpression(callee) && t.isIdentifier(callee.object, { name: "Object" }) && t.isIdentifier(callee.property, { name: "assign" });
|
|
4180
|
+
}
|
|
4177
4181
|
function unwrapDefineComponent(node, aliases) {
|
|
4178
4182
|
if (t.isCallExpression(node) && isDefineComponentCall(node, aliases)) {
|
|
4179
4183
|
const arg = node.arguments[0];
|
|
@@ -4193,6 +4197,7 @@ function resolveComponentExpression(declaration, defineComponentDecls, aliases)
|
|
|
4193
4197
|
}
|
|
4194
4198
|
return null;
|
|
4195
4199
|
}
|
|
4200
|
+
if (t.isCallExpression(declaration) && isObjectAssignCall(declaration)) return declaration;
|
|
4196
4201
|
if (t.isIdentifier(declaration)) {
|
|
4197
4202
|
const matched = defineComponentDecls.get(declaration.name);
|
|
4198
4203
|
return matched ? t.cloneNode(matched, true) : null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"description": "wevu 编译器基础包,面向小程序模板的编译与转换",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@babel/generator": "^7.
|
|
45
|
-
"@babel/parser": "^7.
|
|
46
|
-
"@babel/traverse": "^7.
|
|
47
|
-
"@babel/types": "^7.
|
|
44
|
+
"@babel/generator": "^7.29.0",
|
|
45
|
+
"@babel/parser": "^7.29.0",
|
|
46
|
+
"@babel/traverse": "^7.29.0",
|
|
47
|
+
"@babel/types": "^7.29.0",
|
|
48
48
|
"@vue/compiler-core": "^3.5.27",
|
|
49
49
|
"comment-json": "^4.5.1",
|
|
50
50
|
"fs-extra": "^11.3.3",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"pathe": "^2.0.3",
|
|
55
55
|
"vue": "^3.5.27",
|
|
56
56
|
"@weapp-core/shared": "3.0.0",
|
|
57
|
-
"rolldown-require": "2.0.
|
|
57
|
+
"rolldown-require": "2.0.3"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public",
|