@meituan-nocode/vite-plugin-nocode-compiler 0.1.0-beta.20-z → 0.1.0-beta.21-z
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 +148 -115
- package/dist/index.d.ts +4 -5
- package/dist/index.js +25 -68
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +4 -2
- package/package.json +2 -2
- package/dist/index.cjs.js +0 -1
- package/dist/index.es.js +0 -30
package/README.md
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
# @meituan-nocode/vite-plugin-nocode-compiler
|
|
2
2
|
|
|
3
|
-
Vite
|
|
3
|
+
Vite 插件,用于在构建过程中为 Vue 和 React 组件自动添加属性,支持无代码平台的可视化编辑。
|
|
4
4
|
|
|
5
|
-
## 特性
|
|
5
|
+
## 🚀 特性
|
|
6
6
|
|
|
7
|
-
- ✅ 支持 Vue
|
|
8
|
-
- ✅
|
|
7
|
+
- ✅ 支持 Vue 单文件组件 (`.vue`)
|
|
8
|
+
- ✅ 支持 React JSX/TSX 组件 (`.jsx`, `.tsx`)
|
|
9
|
+
- ✅ 支持 Vue 文件中的 JSX 语法
|
|
10
|
+
- ✅ 支持外部模板文件 (`<template src="xxx.html">`)
|
|
9
11
|
- ✅ 兼容 Vite 4.x 和 5.x 版本
|
|
10
12
|
- ✅ 可配置的日志输出
|
|
11
13
|
- ✅ 支持 ESM 和 CommonJS 导入方式
|
|
14
|
+
- ✅ 自动跳过 `node_modules` 文件
|
|
12
15
|
|
|
13
|
-
## 安装
|
|
16
|
+
## 📦 安装
|
|
14
17
|
|
|
15
18
|
```bash
|
|
16
19
|
# npm
|
|
@@ -23,181 +26,211 @@ yarn add @meituan-nocode/vite-plugin-nocode-compiler --dev
|
|
|
23
26
|
pnpm add @meituan-nocode/vite-plugin-nocode-compiler -D
|
|
24
27
|
```
|
|
25
28
|
|
|
26
|
-
##
|
|
29
|
+
## 🔧 快速开始
|
|
27
30
|
|
|
28
|
-
###
|
|
31
|
+
### 基础配置
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
在项目的 `vite.config.js` 或 `vite.config.ts` 中配置插件:
|
|
31
34
|
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
npm install @meituan-nocode/vite-plugin-nocode-compiler --save-dev
|
|
35
|
-
|
|
36
|
-
# 确保安装了 vite
|
|
37
|
-
npm install vite --save-dev
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### 2. 配置 Vite
|
|
41
|
-
|
|
42
|
-
在测试项目的根目录创建或修改 `vite.config.js` 或 `vite.config.ts` 文件:
|
|
43
|
-
|
|
44
|
-
#### ESM 方式 (推荐)
|
|
45
|
-
|
|
46
|
-
```js
|
|
47
|
-
// vite.config.js / vite.config.ts
|
|
35
|
+
```typescript
|
|
36
|
+
// vite.config.ts
|
|
48
37
|
import { defineConfig } from 'vite';
|
|
49
|
-
import
|
|
50
|
-
// 或者使用默认导出
|
|
51
|
-
// import NocodeCompiler from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
38
|
+
import componentCompiler from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
52
39
|
|
|
53
40
|
export default defineConfig({
|
|
54
41
|
plugins: [
|
|
55
|
-
|
|
56
|
-
enableLogging: true, //
|
|
42
|
+
componentCompiler({
|
|
43
|
+
enableLogging: true, // 开发时建议开启日志
|
|
57
44
|
}),
|
|
58
45
|
],
|
|
59
46
|
});
|
|
60
47
|
```
|
|
61
48
|
|
|
62
|
-
|
|
49
|
+
### CommonJS 配置
|
|
63
50
|
|
|
64
|
-
```
|
|
51
|
+
```javascript
|
|
65
52
|
// vite.config.js
|
|
66
53
|
const { defineConfig } = require('vite');
|
|
67
|
-
const
|
|
54
|
+
const componentCompiler = require('@meituan-nocode/vite-plugin-nocode-compiler').default;
|
|
68
55
|
|
|
69
56
|
module.exports = defineConfig({
|
|
70
57
|
plugins: [
|
|
71
|
-
|
|
72
|
-
enableLogging: true,
|
|
58
|
+
componentCompiler({
|
|
59
|
+
enableLogging: true,
|
|
73
60
|
}),
|
|
74
61
|
],
|
|
75
62
|
});
|
|
76
63
|
```
|
|
77
64
|
|
|
78
|
-
|
|
65
|
+
## ⚙️ 配置选项
|
|
79
66
|
|
|
80
|
-
|
|
67
|
+
| 选项 | 类型 | 默认值 | 描述 |
|
|
68
|
+
| --------------- | --------- | ------- | ------------------------------------------------------ |
|
|
69
|
+
| `enableLogging` | `boolean` | `false` | 是否启用日志输出,开启后会输出详细的处理过程和调试信息 |
|
|
70
|
+
| `rootPath` | `string` | - | 项目根路径,用于生成相对路径标识 |
|
|
81
71
|
|
|
82
|
-
|
|
83
|
-
# 开发模式
|
|
84
|
-
npx vite
|
|
72
|
+
### 配置示例
|
|
85
73
|
|
|
86
|
-
|
|
87
|
-
|
|
74
|
+
```typescript
|
|
75
|
+
// 完整配置示例
|
|
76
|
+
export default defineConfig({
|
|
77
|
+
plugins: [
|
|
78
|
+
componentCompiler({
|
|
79
|
+
enableLogging: process.env.NODE_ENV === 'development',
|
|
80
|
+
rootPath: process.cwd(),
|
|
81
|
+
}),
|
|
82
|
+
],
|
|
83
|
+
});
|
|
88
84
|
```
|
|
89
85
|
|
|
90
|
-
|
|
86
|
+
## 📁 处理的文件类型
|
|
91
87
|
|
|
92
|
-
|
|
88
|
+
### Vue 文件
|
|
93
89
|
|
|
94
|
-
|
|
90
|
+
- `.vue` 单文件组件的 `<template>` 部分
|
|
91
|
+
- Vue 文件中的 JSX/TSX `<script>` 部分
|
|
92
|
+
- 外部模板文件 `<template src="xxx.html">`
|
|
95
93
|
|
|
96
|
-
###
|
|
94
|
+
### React 文件
|
|
97
95
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
import { NocodeCompiler } from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
102
|
-
// 或者使用默认导入
|
|
103
|
-
// import NocodeCompiler from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
96
|
+
- `.jsx` 文件
|
|
97
|
+
- `.tsx` 文件
|
|
98
|
+
- 包含 JSX 语法的 `.js` 和 `.ts` 文件
|
|
104
99
|
|
|
105
|
-
|
|
106
|
-
plugins: [
|
|
107
|
-
NocodeCompiler({
|
|
108
|
-
enableLogging: true,
|
|
109
|
-
// 其他配置选项
|
|
110
|
-
}),
|
|
111
|
-
],
|
|
112
|
-
});
|
|
113
|
-
```
|
|
100
|
+
### 文件处理逻辑
|
|
114
101
|
|
|
115
|
-
|
|
102
|
+
插件会根据文件扩展名和 Vite 查询参数智能判断文件类型:
|
|
116
103
|
|
|
117
|
-
```
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// 或者使用默认导入并解构
|
|
122
|
-
// const pkg = require('@meituan-nocode/vite-plugin-nocode-compiler');
|
|
123
|
-
// const { NocodeCompiler } = pkg;
|
|
104
|
+
```typescript
|
|
105
|
+
// Vue 文件中的 JSX 处理
|
|
106
|
+
// App.vue?type=script&lang.tsx
|
|
107
|
+
// App.vue?isJsx
|
|
124
108
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}),
|
|
131
|
-
],
|
|
132
|
-
});
|
|
109
|
+
// Vue 模板处理
|
|
110
|
+
// App.vue?type=template
|
|
111
|
+
|
|
112
|
+
// 外部模板处理
|
|
113
|
+
// template.html?type=template&vue
|
|
133
114
|
```
|
|
134
115
|
|
|
135
|
-
##
|
|
116
|
+
## 🎯 工作原理
|
|
136
117
|
|
|
137
|
-
|
|
138
|
-
| --------------- | --------- | ------- | ------------------------------------------------------ |
|
|
139
|
-
| `enableLogging` | `boolean` | `false` | 是否启用日志输出,开启后会输出详细的处理过程和调试信息 |
|
|
118
|
+
插件会在构建过程中为符合条件的元素添加以下属性:
|
|
140
119
|
|
|
141
|
-
|
|
120
|
+
```html
|
|
121
|
+
<!-- 处理前 -->
|
|
122
|
+
<div class="container">
|
|
123
|
+
<button>Click me</button>
|
|
124
|
+
</div>
|
|
142
125
|
|
|
143
|
-
|
|
126
|
+
<!-- 处理后 -->
|
|
127
|
+
<div class="container" data-nocode-id="src/App.vue:1:0" data-nocode-path="src/App.vue" data-nocode-line="1" data-nocode-col="0">
|
|
128
|
+
<button data-nocode-id="src/App.vue:2:2" data-nocode-path="src/App.vue" data-nocode-line="2" data-nocode-col="2">Click me</button>
|
|
129
|
+
</div>
|
|
130
|
+
```
|
|
144
131
|
|
|
145
|
-
|
|
146
|
-
- JSX/TSX 文件: `.jsx`, `.tsx` 文件
|
|
147
|
-
- 包含 JSX 语法的 JS/TS 文件: `.js`, `.ts` 文件
|
|
132
|
+
### 添加的属性说明
|
|
148
133
|
|
|
149
|
-
|
|
134
|
+
- `data-nocode-id`: 元素的唯一标识符(格式:`文件路径:行号:列号`)
|
|
135
|
+
- `data-nocode-path`: 相对文件路径
|
|
136
|
+
- `data-nocode-line`: 元素在文件中的行号
|
|
137
|
+
- `data-nocode-col`: 元素在文件中的列号
|
|
138
|
+
- `data-nocode-array`: (可选)当元素在 `v-for` 或 `map` 循环中时,标识数组名称
|
|
150
139
|
|
|
151
|
-
|
|
140
|
+
## 🏗️ 在 Monorepo 项目中使用
|
|
152
141
|
|
|
153
|
-
|
|
154
|
-
- JSX 组件编译器 (`JSXCompiler`)
|
|
155
|
-
- 代码转换器 (`CodeTransformer`)
|
|
142
|
+
在 monorepo 项目中,建议在共享配置中定义插件:
|
|
156
143
|
|
|
157
|
-
|
|
144
|
+
```typescript
|
|
145
|
+
// packages/shared/vite-config.ts
|
|
146
|
+
import { defineConfig } from 'vite';
|
|
147
|
+
import componentCompiler from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
148
|
+
|
|
149
|
+
export const createViteConfig = (options: { enableLogging?: boolean } = {}) => {
|
|
150
|
+
return defineConfig({
|
|
151
|
+
plugins: [
|
|
152
|
+
componentCompiler({
|
|
153
|
+
enableLogging: options.enableLogging ?? process.env.NODE_ENV === 'development',
|
|
154
|
+
}),
|
|
155
|
+
],
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// 子项目中使用
|
|
160
|
+
// packages/app-a/vite.config.ts
|
|
161
|
+
import { createViteConfig } from '@shared/vite-config';
|
|
162
|
+
|
|
163
|
+
export default createViteConfig({ enableLogging: true });
|
|
164
|
+
```
|
|
158
165
|
|
|
159
|
-
|
|
166
|
+
## 🐛 调试和故障排除
|
|
160
167
|
|
|
161
|
-
|
|
162
|
-
// 子项目的 vite.config.js
|
|
163
|
-
import { defineConfig } from 'vite';
|
|
164
|
-
import { NocodeCompiler } from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
168
|
+
### 启用调试日志
|
|
165
169
|
|
|
170
|
+
```typescript
|
|
171
|
+
// vite.config.ts
|
|
166
172
|
export default defineConfig({
|
|
167
173
|
plugins: [
|
|
168
|
-
|
|
169
|
-
enableLogging: true,
|
|
174
|
+
componentCompiler({
|
|
175
|
+
enableLogging: true, // 开启详细日志
|
|
170
176
|
}),
|
|
171
177
|
],
|
|
172
178
|
});
|
|
173
179
|
```
|
|
174
180
|
|
|
175
|
-
|
|
181
|
+
开启后,构建时会输出类似日志:
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
[vite-plugin-nocode-compiler] Processing Vue file: src/App.vue
|
|
185
|
+
[vue-compiler] File processing complete 5
|
|
186
|
+
[vite-plugin-nocode-compiler] Processing JSX file: src/components/Button.tsx
|
|
187
|
+
[jsx-compiler] File processing complete 3
|
|
188
|
+
```
|
|
176
189
|
|
|
177
|
-
###
|
|
190
|
+
### 常见问题
|
|
178
191
|
|
|
179
|
-
|
|
192
|
+
#### Q: 插件没有生效怎么办?
|
|
180
193
|
|
|
181
|
-
|
|
194
|
+
A: 检查以下几点:
|
|
182
195
|
|
|
183
|
-
|
|
196
|
+
1. 确认插件已正确安装和配置
|
|
197
|
+
2. 确保 `enforce: 'pre'` 设置正确(插件已内置)
|
|
198
|
+
3. 检查文件是否在 `node_modules` 中(插件会自动跳过)
|
|
199
|
+
4. 开启 `enableLogging` 查看是否有处理日志
|
|
184
200
|
|
|
185
|
-
|
|
186
|
-
- React 框架: `.jsx`, `.tsx` 文件,以及包含 JSX 语法的 `.js`, `.ts` 文件
|
|
201
|
+
#### Q: 某些文件没有被处理?
|
|
187
202
|
|
|
188
|
-
|
|
203
|
+
A: 可能的原因:
|
|
189
204
|
|
|
190
|
-
|
|
205
|
+
- 文件在 `node_modules` 目录下
|
|
206
|
+
- 文件类型不支持(如纯 CSS 文件)
|
|
207
|
+
- Vue 文件的 `<style>` 部分(插件只处理模板和脚本)
|
|
191
208
|
|
|
192
|
-
|
|
209
|
+
#### Q: 如何排除特定文件?
|
|
193
210
|
|
|
194
|
-
A:
|
|
211
|
+
A: 目前插件没有内置排除选项,但可以通过 Vite 的 `optimizeDeps` 或自定义插件来实现:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
export default defineConfig({
|
|
215
|
+
plugins: [
|
|
216
|
+
componentCompiler(),
|
|
217
|
+
// 自定义插件排除特定文件
|
|
218
|
+
{
|
|
219
|
+
name: 'exclude-files',
|
|
220
|
+
transform(code, id) {
|
|
221
|
+
if (id.includes('excluded-folder')) {
|
|
222
|
+
return null; // 跳过处理
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
});
|
|
228
|
+
```
|
|
195
229
|
|
|
196
|
-
|
|
197
|
-
2. 开启 `enableLogging: true` 查看详细日志
|
|
198
|
-
3. 检查项目中是否有需要处理的 Vue 或 JSX/TSX 文件
|
|
199
|
-
4. 确认 Vite 版本兼容性(支持 Vite 4.x 和 5.x)
|
|
230
|
+
## 📚 依赖关系
|
|
200
231
|
|
|
201
|
-
|
|
232
|
+
该插件依赖于以下核心包:
|
|
202
233
|
|
|
203
|
-
|
|
234
|
+
- `@meituan-nocode/nocode-compiler-core`: 提供核心编译逻辑
|
|
235
|
+
- `VueCompiler`: Vue 组件编译器
|
|
236
|
+
- `JSXCompiler`: JSX 组件编译器
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
export interface NocodeCompilerOptions {
|
|
2
2
|
enableLogging?: boolean;
|
|
3
|
-
|
|
3
|
+
rootPath?: string;
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
6
|
* Vite插件
|
|
7
7
|
* 用于在构建过程中处理Vue和React组件,添加nocode相关的标记
|
|
8
|
-
* 兼容 Vite 4.x 和 5.x 版本
|
|
9
8
|
*/
|
|
10
|
-
export declare function
|
|
9
|
+
export declare function componentCompiler(options?: NocodeCompilerOptions): {
|
|
11
10
|
name: string;
|
|
12
11
|
enforce: "pre";
|
|
13
|
-
transform(code: string, id: string): Promise<string
|
|
12
|
+
transform(code: string, id: string): Promise<string>;
|
|
14
13
|
};
|
|
15
|
-
export default
|
|
14
|
+
export default componentCompiler;
|
package/dist/index.js
CHANGED
|
@@ -1,103 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
37
|
-
const
|
|
38
|
-
const { CodeTransformer } = compilerCore;
|
|
3
|
+
exports.componentCompiler = componentCompiler;
|
|
4
|
+
const nocode_compiler_core_1 = require("@meituan-nocode/nocode-compiler-core");
|
|
39
5
|
const utils_1 = require("./utils");
|
|
40
|
-
// 检查是否安装了@vue/compiler-dom
|
|
41
|
-
let vueCompilerAvailable = false;
|
|
42
|
-
try {
|
|
43
|
-
require('@vue/compiler-dom');
|
|
44
|
-
vueCompilerAvailable = true;
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
console.warn('[vite-plugin-nocode-compiler] @vue/compiler-dom not found. Vue compilation will be skipped.');
|
|
48
|
-
}
|
|
49
6
|
/**
|
|
50
7
|
* Vite插件
|
|
51
8
|
* 用于在构建过程中处理Vue和React组件,添加nocode相关的标记
|
|
52
|
-
* 兼容 Vite 4.x 和 5.x 版本
|
|
53
9
|
*/
|
|
54
|
-
function
|
|
10
|
+
function componentCompiler(options = {}) {
|
|
55
11
|
options = {
|
|
56
12
|
enableLogging: false,
|
|
57
|
-
entryFileMarker: false,
|
|
58
13
|
...options,
|
|
59
14
|
};
|
|
60
15
|
// 创建代码转换器实例
|
|
61
|
-
const codeTransformer = new CodeTransformer(options);
|
|
16
|
+
// const codeTransformer = new CodeTransformer(options);
|
|
17
|
+
const vueCompiler = new nocode_compiler_core_1.VueCompiler(options);
|
|
18
|
+
const jsxCompiler = new nocode_compiler_core_1.JSXCompiler(options);
|
|
62
19
|
return {
|
|
63
20
|
name: 'vite-plugin-nocode-compiler',
|
|
64
21
|
enforce: 'pre',
|
|
65
22
|
async transform(code, id) {
|
|
66
23
|
// 跳过node_modules
|
|
67
24
|
if (id.includes('node_modules')) {
|
|
68
|
-
return
|
|
25
|
+
return code;
|
|
69
26
|
}
|
|
70
27
|
const [_completePath, query] = id.split('?', 2); // 当前文件的绝对路径
|
|
71
28
|
let filePath = _completePath;
|
|
72
29
|
const params = new URLSearchParams(query);
|
|
73
|
-
let fileType = '';
|
|
74
|
-
if ((0, utils_1.isJsTypeFile)(filePath) || (filePath.endsWith('.vue') && (utils_1.
|
|
30
|
+
// let fileType = '';
|
|
31
|
+
if ((0, utils_1.isJsTypeFile)(filePath) || (filePath.endsWith('.vue') && (utils_1.JsxParamList.some(param => params.get(param) !== null) || params.get('lang') === 'tsx' || params.get('lang') === 'jsx'))) {
|
|
75
32
|
// jsx 代码
|
|
76
|
-
|
|
33
|
+
return jsxCompiler.compile(code, filePath) || code;
|
|
77
34
|
}
|
|
78
35
|
else if (filePath.endsWith('.html') && params.get('type') === 'template' && params.has('vue')) {
|
|
79
36
|
// <template src="xxx.html"></template>
|
|
80
|
-
|
|
37
|
+
return vueCompiler.compile(code, filePath) || code;
|
|
81
38
|
}
|
|
82
39
|
else if (filePath.endsWith('.vue') && params.get('type') !== 'style' && params.get('raw') === null) {
|
|
83
40
|
// vue 代码
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
// 如果是Vue文件但@vue/compiler-dom不可用,跳过处理
|
|
87
|
-
if (fileType === 'vue' && !vueCompilerAvailable) {
|
|
88
|
-
console.warn(`[vite-plugin-nocode-compiler] Skipping Vue file processing for ${filePath} due to missing @vue/compiler-dom`);
|
|
89
|
-
return code;
|
|
90
|
-
}
|
|
91
|
-
if (fileType) {
|
|
92
|
-
return codeTransformer.transformCode({
|
|
93
|
-
content: code,
|
|
94
|
-
filePath,
|
|
95
|
-
fileType,
|
|
96
|
-
});
|
|
41
|
+
return vueCompiler.compile(code, filePath) || code;
|
|
97
42
|
}
|
|
43
|
+
// // 如果是Vue文件但@vue/compiler-dom不可用,跳过处理
|
|
44
|
+
// if (fileType === 'vue' && !vueCompilerAvailable) {
|
|
45
|
+
// console.warn(`[vite-plugin-nocode-compiler] Skipping Vue file processing for ${filePath} due to missing @vue/compiler-dom`);
|
|
46
|
+
// return code;
|
|
47
|
+
// }
|
|
48
|
+
// if (fileType) {
|
|
49
|
+
// return codeTransformer.transformCode({
|
|
50
|
+
// content: code,
|
|
51
|
+
// filePath,
|
|
52
|
+
// fileType,
|
|
53
|
+
// });
|
|
54
|
+
// }
|
|
98
55
|
return code;
|
|
99
56
|
},
|
|
100
57
|
};
|
|
101
58
|
}
|
|
102
59
|
// 添加默认导出,使 ESM 导入更方便
|
|
103
|
-
exports.default =
|
|
60
|
+
exports.default = componentCompiler;
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.JsxParamList = exports.JsFileExtList = void 0;
|
|
4
4
|
exports.isJsTypeFile = isJsTypeFile;
|
|
5
5
|
exports.normalizePath = normalizePath;
|
|
6
6
|
exports.JsFileExtList = ['.js', '.ts', '.mjs', '.mts', '.jsx', '.tsx'];
|
|
7
|
-
exports.
|
|
7
|
+
exports.JsxParamList = ['isJsx', 'isTsx', 'lang.jsx', 'lang.tsx'];
|
|
8
8
|
// 是否为 JS 类型的文件
|
|
9
9
|
function isJsTypeFile(file) {
|
|
10
10
|
return exports.JsFileExtList.some(ext => file.endsWith(ext));
|
|
@@ -15,5 +15,7 @@ function isJsTypeFile(file) {
|
|
|
15
15
|
* @returns 规范化后的路径
|
|
16
16
|
*/
|
|
17
17
|
function normalizePath(filePath) {
|
|
18
|
+
if (!filePath)
|
|
19
|
+
return '';
|
|
18
20
|
return filePath.replace(/\\/g, '/');
|
|
19
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meituan-nocode/vite-plugin-nocode-compiler",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.21-z",
|
|
4
4
|
"description": "nocode compiler plugin",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"vite": "^4.5.14"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@meituan-nocode/nocode-compiler-core": "0.1.0-beta.
|
|
30
|
+
"@meituan-nocode/nocode-compiler-core": "0.1.0-beta.21-z"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/dist/index.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("@meituan-nocode/nocode-compiler-core");function f(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const p=f(m),d=[".js",".ts",".mjs",".mts",".jsx",".tsx"],g=["isJsx","isTsx","lang.jsx","lang.tsx"];function j(e){return d.some(t=>e.endsWith(t))}const{CodeTransformer:x}=p;function i(e={}){const t=new x(e);return{name:"vite-plugin-nocode-compiler",enforce:"pre",async transform(n,r){if(r.includes("node_modules"))return null;const[a,u]=r.split("?",2);let o=a;const s=new URLSearchParams(u);let l="";return j(o)||o.endsWith(".vue")&&(g.some(c=>s.get(c)!==null)||s.get("lang")==="tsx"||s.get("lang")==="jsx")?l="jsx":(o.endsWith(".html")&&s.get("type")==="template"&&s.has("vue")||o.endsWith(".vue")&&s.get("type")!=="style"&&s.get("raw")===null)&&(l="vue"),l?t.transformCode({content:n,filePath:o,fileType:l}):n}}}exports.NocodeCompiler=i;exports.default=i;
|
package/dist/index.es.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as u from "@meituan-nocode/nocode-compiler-core";
|
|
2
|
-
const c = [".js", ".ts", ".mjs", ".mts", ".jsx", ".tsx"], f = ["isJsx", "isTsx", "lang.jsx", "lang.tsx"];
|
|
3
|
-
function p(n) {
|
|
4
|
-
return c.some((r) => n.endsWith(r));
|
|
5
|
-
}
|
|
6
|
-
const { CodeTransformer: x } = u;
|
|
7
|
-
function d(n = {}) {
|
|
8
|
-
const r = new x(n);
|
|
9
|
-
return {
|
|
10
|
-
name: "vite-plugin-nocode-compiler",
|
|
11
|
-
enforce: "pre",
|
|
12
|
-
async transform(o, l) {
|
|
13
|
-
if (l.includes("node_modules"))
|
|
14
|
-
return null;
|
|
15
|
-
const [i, a] = l.split("?", 2);
|
|
16
|
-
let t = i;
|
|
17
|
-
const e = new URLSearchParams(a);
|
|
18
|
-
let s = "";
|
|
19
|
-
return p(t) || t.endsWith(".vue") && (f.some((m) => e.get(m) !== null) || e.get("lang") === "tsx" || e.get("lang") === "jsx") ? s = "jsx" : (t.endsWith(".html") && e.get("type") === "template" && e.has("vue") || t.endsWith(".vue") && e.get("type") !== "style" && e.get("raw") === null) && (s = "vue"), s ? r.transformCode({
|
|
20
|
-
content: o,
|
|
21
|
-
filePath: t,
|
|
22
|
-
fileType: s
|
|
23
|
-
}) : o;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
export {
|
|
28
|
-
d as NocodeCompiler,
|
|
29
|
-
d as default
|
|
30
|
-
};
|