uview-pro 0.6.12 → 0.6.14
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/changelog.md +32 -2
- package/components/u-picker/u-picker.vue +16 -18
- package/components/u-select/u-select.vue +7 -6
- package/index.ts +100 -100
- package/package.json +2 -11
- package/plugins/root/README.md +161 -161
- package/plugins/root/dist/page.cjs +29 -11
- package/plugins/root/dist/page.mjs +29 -11
- package/plugins/root/dist/root.cjs +10 -2
- package/plugins/root/dist/root.mjs +10 -2
- package/plugins/root/dist/utils.cjs +1 -1
- package/plugins/root/dist/utils.mjs +1 -1
- package/plugins/root/index.ts +123 -123
- package/plugins/root/page.ts +77 -54
- package/plugins/root/root.ts +53 -35
- package/plugins/root/utils.ts +137 -133
- package/readme.md +2 -2
- package/types/index.d.ts +14 -19
package/plugins/root/README.md
CHANGED
|
@@ -1,161 +1,161 @@
|
|
|
1
|
-
# vite-plugin-uni-root
|
|
2
|
-
|
|
3
|
-
UniApp 虚拟根组件 Vite 插件,零额外依赖,纯字符串操作实现。
|
|
4
|
-
|
|
5
|
-
## 解决的问题
|
|
6
|
-
|
|
7
|
-
UniApp 不支持原生的根组件包裹机制,无法在全局统一注入 `u-config-provider`、`u-toast`、`u-modal` 等需要在每个页面根部存在的组件。传统方案需要在每个页面手动添加,维护成本高。
|
|
8
|
-
|
|
9
|
-
本插件通过 Vite 构建时注入,自动为每个页面包裹 `<global-root-view>` 根组件,无需修改任何页面代码本身。
|
|
10
|
-
|
|
11
|
-
## 技术方案
|
|
12
|
-
|
|
13
|
-
### 架构
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
App.root.vue(源码) → 在 main.ts 中导入并注册为全局组件 global-root-view
|
|
17
|
-
→ 页面模板被包裹 <global-root-view> 页面内容 </global-root-view>
|
|
18
|
-
→ 渲染时页面内容填入 <slot />
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### 工作流程
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
┌─────────────┐ ┌──────────────┐ ┌─────────────────┐
|
|
25
|
-
│ main.ts │ → │ 注入 import │ → │ 全局注册组件 │
|
|
26
|
-
│ │ │ + 注册代码 │ │ global-root-view │
|
|
27
|
-
└─────────────┘ └──────────────┘ └─────────────────┘
|
|
28
|
-
│
|
|
29
|
-
┌─────────────┐ ┌──────────────┐ │
|
|
30
|
-
│ page.vue │ → │ 包裹模板 │ │
|
|
31
|
-
│ │ │ <global-...> │ ←─────────┘
|
|
32
|
-
└─────────────┘ └──────────────┘
|
|
33
|
-
│
|
|
34
|
-
┌─────────────┐ │
|
|
35
|
-
│ App.root.vue│ → <slot /> 接收页面内容
|
|
36
|
-
└─────────────┘
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### 三步实现
|
|
40
|
-
|
|
41
|
-
1. **main.ts 注入**(`root.ts -> registerRootApp`)
|
|
42
|
-
- 在 main.ts 中注入 `import GlobalRootView from "./App.root.vue"`
|
|
43
|
-
- 注入 `app.component("global-root-view", GlobalRootView)` 注册为全局组件
|
|
44
|
-
- 注:`GlobalRootView` 仅为局部变量名,实际组件就是 `App.root.vue`
|
|
45
|
-
|
|
46
|
-
2. **页面模板包裹**(`page.ts -> transformPage`)
|
|
47
|
-
- 解析 SFC,定位 `<template>` 标签的起止位置
|
|
48
|
-
- 提取 PageMeta 节点(如有则放到包裹层外部)
|
|
49
|
-
- 将模板内容包裹在 `<global-root-view>...</global-root-view>` 中
|
|
50
|
-
|
|
51
|
-
3. **App.root.vue 加载**(`index.ts -> load`)
|
|
52
|
-
- 拦截 `App.root.vue` 的模块请求,从文件读取并返回
|
|
53
|
-
- 模板中的 `<slot />` 接收并渲染页面内容
|
|
54
|
-
|
|
55
|
-
### 跨端兼容
|
|
56
|
-
|
|
57
|
-
插件是纯 Vite 构建时插件,在 UniApp 编译之前完成源代码转换,不依赖任何平台特定 API,所有 UniApp 支持的平台均可正常工作:
|
|
58
|
-
|
|
59
|
-
| 平台 | 支持 |
|
|
60
|
-
|------|------|
|
|
61
|
-
| H5 | ✅ |
|
|
62
|
-
| 微信小程序 | ✅ |
|
|
63
|
-
| 支付宝小程序 | ✅ |
|
|
64
|
-
| 头条/抖音小程序 | ✅ |
|
|
65
|
-
| Android App | ✅ |
|
|
66
|
-
| iOS App | ✅ |
|
|
67
|
-
| 鸿蒙 App | ✅ |
|
|
68
|
-
|
|
69
|
-
## 使用方式
|
|
70
|
-
|
|
71
|
-
### 1. 创建 App.root.vue
|
|
72
|
-
|
|
73
|
-
在 `src/` 目录下创建 `App.root.vue` 文件:
|
|
74
|
-
|
|
75
|
-
```vue
|
|
76
|
-
<script setup lang="ts">
|
|
77
|
-
import { onLoad } from '@dcloudio/uni-app';
|
|
78
|
-
import { useTheme, useLocale } from 'uview-pro';
|
|
79
|
-
|
|
80
|
-
const { darkMode, themes, currentTheme } = useTheme();
|
|
81
|
-
const { currentLocale } = useLocale();
|
|
82
|
-
|
|
83
|
-
onLoad(() => {
|
|
84
|
-
console.log('darkMode->', darkMode.value);
|
|
85
|
-
console.log('theme->', currentTheme.value?.name);
|
|
86
|
-
console.log('locale->', currentLocale.value?.name);
|
|
87
|
-
});
|
|
88
|
-
</script>
|
|
89
|
-
|
|
90
|
-
<template>
|
|
91
|
-
<u-config-provider
|
|
92
|
-
:dark-mode="darkMode"
|
|
93
|
-
:themes="themes"
|
|
94
|
-
:current-theme="currentTheme?.name"
|
|
95
|
-
:current-locale="currentLocale?.name"
|
|
96
|
-
>
|
|
97
|
-
<slot />
|
|
98
|
-
<u-toast global></u-toast>
|
|
99
|
-
<u-modal global></u-modal>
|
|
100
|
-
</u-config-provider>
|
|
101
|
-
</template>
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
关键点:`<slot />` 是页面内容的渲染位置,必须保留。
|
|
105
|
-
|
|
106
|
-
### 2. 配置 vite.config.ts
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
// npm 安装
|
|
110
|
-
import { UniRoot } from 'uview-pro/plugins';
|
|
111
|
-
|
|
112
|
-
// uni_modules 安装
|
|
113
|
-
import { UniRoot } from './src/uni_modules/uview-pro/plugins';
|
|
114
|
-
|
|
115
|
-
export default defineConfig({
|
|
116
|
-
plugins: [
|
|
117
|
-
UniRoot(), // 放在其他插件之前
|
|
118
|
-
// ...其他插件
|
|
119
|
-
],
|
|
120
|
-
});
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### 3. 运行
|
|
124
|
-
|
|
125
|
-
```bash
|
|
126
|
-
npm run dev
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
不需要修改任何页面代码,所有页面自动被 `<global-root-view>` 包裹。
|
|
130
|
-
|
|
131
|
-
## 文件结构
|
|
132
|
-
|
|
133
|
-
```
|
|
134
|
-
src/uni_modules/uview-pro/plugins/root/
|
|
135
|
-
├── index.ts # 插件入口,Vite 插件生命周期
|
|
136
|
-
├── root.ts # main.ts 注入 + App.root.vue 处理
|
|
137
|
-
├── page.ts # 页面模板包裹转换
|
|
138
|
-
└── utils.ts # 工具函数(SFC 解析、pages.json 加载、AST 查找等)
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
## 配置项
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
UniRoot({
|
|
145
|
-
rootFileName: 'App.root', // 根组件文件名(不含扩展名),默认 App.root
|
|
146
|
-
})
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
## HMR 支持
|
|
150
|
-
|
|
151
|
-
修改 `pages.json` 后自动重载页面列表,无需手动重启开发服务器。
|
|
152
|
-
|
|
153
|
-
## 注意事项
|
|
154
|
-
|
|
155
|
-
- Vue 版本需 >= 3.2.13(使用 `vue/compiler-sfc` 的 `parse` API
|
|
156
|
-
- 页面模板中如有 `<page-meta>` 组件,会被提取到包裹层外部,确保微信小程序兼容
|
|
157
|
-
- 页面模板中如有嵌套 `<template #slot>` 具名插槽,不影响根模板的正确识别
|
|
158
|
-
|
|
159
|
-
## 致谢
|
|
160
|
-
|
|
161
|
-
本插件的实现参考了 [@uni-ku/root](https://github.com/uni-ku/root)(MIT License,作者 skiyee),核心思路受其启发并进行了重新实现。
|
|
1
|
+
# vite-plugin-uni-root
|
|
2
|
+
|
|
3
|
+
UniApp 虚拟根组件 Vite 插件,零额外依赖,纯字符串操作实现。
|
|
4
|
+
|
|
5
|
+
## 解决的问题
|
|
6
|
+
|
|
7
|
+
UniApp 不支持原生的根组件包裹机制,无法在全局统一注入 `u-config-provider`、`u-toast`、`u-modal` 等需要在每个页面根部存在的组件。传统方案需要在每个页面手动添加,维护成本高。
|
|
8
|
+
|
|
9
|
+
本插件通过 Vite 构建时注入,自动为每个页面包裹 `<global-root-view>` 根组件,无需修改任何页面代码本身。
|
|
10
|
+
|
|
11
|
+
## 技术方案
|
|
12
|
+
|
|
13
|
+
### 架构
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
App.root.vue(源码) → 在 main.ts 中导入并注册为全局组件 global-root-view
|
|
17
|
+
→ 页面模板被包裹 <global-root-view> 页面内容 </global-root-view>
|
|
18
|
+
→ 渲染时页面内容填入 <slot />
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 工作流程
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
┌─────────────┐ ┌──────────────┐ ┌─────────────────┐
|
|
25
|
+
│ main.ts │ → │ 注入 import │ → │ 全局注册组件 │
|
|
26
|
+
│ │ │ + 注册代码 │ │ global-root-view │
|
|
27
|
+
└─────────────┘ └──────────────┘ └─────────────────┘
|
|
28
|
+
│
|
|
29
|
+
┌─────────────┐ ┌──────────────┐ │
|
|
30
|
+
│ page.vue │ → │ 包裹模板 │ │
|
|
31
|
+
│ │ │ <global-...> │ ←─────────┘
|
|
32
|
+
└─────────────┘ └──────────────┘
|
|
33
|
+
│
|
|
34
|
+
┌─────────────┐ │
|
|
35
|
+
│ App.root.vue│ → <slot /> 接收页面内容
|
|
36
|
+
└─────────────┘
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 三步实现
|
|
40
|
+
|
|
41
|
+
1. **main.ts 注入**(`root.ts -> registerRootApp`)
|
|
42
|
+
- 在 main.ts 中注入 `import GlobalRootView from "./App.root.vue"`
|
|
43
|
+
- 注入 `app.component("global-root-view", GlobalRootView)` 注册为全局组件
|
|
44
|
+
- 注:`GlobalRootView` 仅为局部变量名,实际组件就是 `App.root.vue`
|
|
45
|
+
|
|
46
|
+
2. **页面模板包裹**(`page.ts -> transformPage`)
|
|
47
|
+
- 解析 SFC,定位 `<template>` 标签的起止位置
|
|
48
|
+
- 提取 PageMeta 节点(如有则放到包裹层外部)
|
|
49
|
+
- 将模板内容包裹在 `<global-root-view>...</global-root-view>` 中
|
|
50
|
+
|
|
51
|
+
3. **App.root.vue 加载**(`index.ts -> load`)
|
|
52
|
+
- 拦截 `App.root.vue` 的模块请求,从文件读取并返回
|
|
53
|
+
- 模板中的 `<slot />` 接收并渲染页面内容
|
|
54
|
+
|
|
55
|
+
### 跨端兼容
|
|
56
|
+
|
|
57
|
+
插件是纯 Vite 构建时插件,在 UniApp 编译之前完成源代码转换,不依赖任何平台特定 API,所有 UniApp 支持的平台均可正常工作:
|
|
58
|
+
|
|
59
|
+
| 平台 | 支持 |
|
|
60
|
+
|------|------|
|
|
61
|
+
| H5 | ✅ |
|
|
62
|
+
| 微信小程序 | ✅ |
|
|
63
|
+
| 支付宝小程序 | ✅ |
|
|
64
|
+
| 头条/抖音小程序 | ✅ |
|
|
65
|
+
| Android App | ✅ |
|
|
66
|
+
| iOS App | ✅ |
|
|
67
|
+
| 鸿蒙 App | ✅ |
|
|
68
|
+
|
|
69
|
+
## 使用方式
|
|
70
|
+
|
|
71
|
+
### 1. 创建 App.root.vue
|
|
72
|
+
|
|
73
|
+
在 `src/` 目录下创建 `App.root.vue` 文件:
|
|
74
|
+
|
|
75
|
+
```vue
|
|
76
|
+
<script setup lang="ts">
|
|
77
|
+
import { onLoad } from '@dcloudio/uni-app';
|
|
78
|
+
import { useTheme, useLocale } from 'uview-pro';
|
|
79
|
+
|
|
80
|
+
const { darkMode, themes, currentTheme } = useTheme();
|
|
81
|
+
const { currentLocale } = useLocale();
|
|
82
|
+
|
|
83
|
+
onLoad(() => {
|
|
84
|
+
console.log('darkMode->', darkMode.value);
|
|
85
|
+
console.log('theme->', currentTheme.value?.name);
|
|
86
|
+
console.log('locale->', currentLocale.value?.name);
|
|
87
|
+
});
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<template>
|
|
91
|
+
<u-config-provider
|
|
92
|
+
:dark-mode="darkMode"
|
|
93
|
+
:themes="themes"
|
|
94
|
+
:current-theme="currentTheme?.name"
|
|
95
|
+
:current-locale="currentLocale?.name"
|
|
96
|
+
>
|
|
97
|
+
<slot />
|
|
98
|
+
<u-toast global></u-toast>
|
|
99
|
+
<u-modal global></u-modal>
|
|
100
|
+
</u-config-provider>
|
|
101
|
+
</template>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
关键点:`<slot />` 是页面内容的渲染位置,必须保留。
|
|
105
|
+
|
|
106
|
+
### 2. 配置 vite.config.ts
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
// npm 安装
|
|
110
|
+
import { UniRoot } from 'uview-pro/plugins';
|
|
111
|
+
|
|
112
|
+
// uni_modules 安装
|
|
113
|
+
import { UniRoot } from './src/uni_modules/uview-pro/plugins';
|
|
114
|
+
|
|
115
|
+
export default defineConfig({
|
|
116
|
+
plugins: [
|
|
117
|
+
UniRoot(), // 放在其他插件之前
|
|
118
|
+
// ...其他插件
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 3. 运行
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm run dev
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
不需要修改任何页面代码,所有页面自动被 `<global-root-view>` 包裹。
|
|
130
|
+
|
|
131
|
+
## 文件结构
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
src/uni_modules/uview-pro/plugins/root/
|
|
135
|
+
├── index.ts # 插件入口,Vite 插件生命周期
|
|
136
|
+
├── root.ts # main.ts 注入 + App.root.vue 处理
|
|
137
|
+
├── page.ts # 页面模板包裹转换
|
|
138
|
+
└── utils.ts # 工具函数(SFC 解析、pages.json 加载、AST 查找等)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## 配置项
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
UniRoot({
|
|
145
|
+
rootFileName: 'App.root', // 根组件文件名(不含扩展名),默认 App.root
|
|
146
|
+
})
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## HMR 支持
|
|
150
|
+
|
|
151
|
+
修改 `pages.json` 后自动重载页面列表,无需手动重启开发服务器。
|
|
152
|
+
|
|
153
|
+
## 注意事项
|
|
154
|
+
|
|
155
|
+
- Vue 版本需 >= 3.2.13(使用 `vue/compiler-sfc` 的 `parse` API,HBuilderX 环境下自动降级为正则匹配)
|
|
156
|
+
- 页面模板中如有 `<page-meta>` 组件,会被提取到包裹层外部,确保微信小程序兼容
|
|
157
|
+
- 页面模板中如有嵌套 `<template #slot>` 具名插槽,不影响根模板的正确识别
|
|
158
|
+
|
|
159
|
+
## 致谢
|
|
160
|
+
|
|
161
|
+
本插件的实现参考了 [@uni-ku/root](https://github.com/uni-ku/root)(MIT License,作者 skiyee),核心思路受其启发并进行了重新实现。
|
|
@@ -23,8 +23,6 @@ module.exports = __toCommonJS(page_exports);
|
|
|
23
23
|
var import_utils = require("./utils.cjs");
|
|
24
24
|
async function transformPage(code) {
|
|
25
25
|
const sfc = await (0, import_utils.parseSFC)(code);
|
|
26
|
-
if (!sfc.template)
|
|
27
|
-
return null;
|
|
28
26
|
const openMatch = code.match(/<template\b[^>]*>/);
|
|
29
27
|
if (!openMatch)
|
|
30
28
|
return null;
|
|
@@ -33,23 +31,43 @@ async function transformPage(code) {
|
|
|
33
31
|
return null;
|
|
34
32
|
const openTagEnd = openMatch.index + openMatch[0].length;
|
|
35
33
|
const content = code.slice(openTagEnd, closeTagStart);
|
|
36
|
-
const pageMetaNode = (0, import_utils.findNode)(sfc, "PageMeta");
|
|
37
34
|
let pageMetaSource = "";
|
|
38
35
|
let newContent = content;
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
if (sfc == null ? void 0 : sfc.template) {
|
|
37
|
+
const pageMetaNode = (0, import_utils.findNode)(sfc, "PageMeta");
|
|
38
|
+
if (pageMetaNode) {
|
|
39
|
+
pageMetaSource = pageMetaNode.loc.source;
|
|
40
|
+
const metaStart = pageMetaNode.loc.start.offset;
|
|
41
|
+
const metaEnd = pageMetaNode.loc.end.offset;
|
|
42
|
+
const metaStartInContent = metaStart - openTagEnd;
|
|
43
|
+
const metaEndInContent = metaEnd - openTagEnd;
|
|
44
|
+
newContent = content.slice(0, metaStartInContent) + content.slice(metaEndInContent);
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
const pageMetaMatch = content.match(/<page-meta\b[^>]*>[\s\S]*?<\/page-meta>/);
|
|
48
|
+
if (pageMetaMatch) {
|
|
49
|
+
pageMetaSource = pageMetaMatch[0];
|
|
50
|
+
newContent = content.replace(pageMetaMatch[0], "");
|
|
51
|
+
} else {
|
|
52
|
+
const selfClosingMatch = content.match(/<page-meta\b[^>]*\/>/);
|
|
53
|
+
if (selfClosingMatch) {
|
|
54
|
+
pageMetaSource = selfClosingMatch[0];
|
|
55
|
+
newContent = content.replace(selfClosingMatch[0], "");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
46
58
|
}
|
|
47
59
|
const wrappedContent = `
|
|
48
60
|
${pageMetaSource}
|
|
49
61
|
<global-root-view>${newContent}</global-root-view>
|
|
50
62
|
`;
|
|
51
63
|
return {
|
|
52
|
-
code: code.slice(0, openTagEnd) + wrappedContent + code.slice(closeTagStart)
|
|
64
|
+
code: code.slice(0, openTagEnd) + wrappedContent + code.slice(closeTagStart),
|
|
65
|
+
map: {
|
|
66
|
+
version: 3,
|
|
67
|
+
sources: [],
|
|
68
|
+
names: [],
|
|
69
|
+
mappings: ""
|
|
70
|
+
}
|
|
53
71
|
};
|
|
54
72
|
}
|
|
55
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { parseSFC, findNode } from "./utils.mjs";
|
|
2
2
|
async function transformPage(code) {
|
|
3
3
|
const sfc = await parseSFC(code);
|
|
4
|
-
if (!sfc.template)
|
|
5
|
-
return null;
|
|
6
4
|
const openMatch = code.match(/<template\b[^>]*>/);
|
|
7
5
|
if (!openMatch)
|
|
8
6
|
return null;
|
|
@@ -11,23 +9,43 @@ async function transformPage(code) {
|
|
|
11
9
|
return null;
|
|
12
10
|
const openTagEnd = openMatch.index + openMatch[0].length;
|
|
13
11
|
const content = code.slice(openTagEnd, closeTagStart);
|
|
14
|
-
const pageMetaNode = findNode(sfc, "PageMeta");
|
|
15
12
|
let pageMetaSource = "";
|
|
16
13
|
let newContent = content;
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
if (sfc == null ? void 0 : sfc.template) {
|
|
15
|
+
const pageMetaNode = findNode(sfc, "PageMeta");
|
|
16
|
+
if (pageMetaNode) {
|
|
17
|
+
pageMetaSource = pageMetaNode.loc.source;
|
|
18
|
+
const metaStart = pageMetaNode.loc.start.offset;
|
|
19
|
+
const metaEnd = pageMetaNode.loc.end.offset;
|
|
20
|
+
const metaStartInContent = metaStart - openTagEnd;
|
|
21
|
+
const metaEndInContent = metaEnd - openTagEnd;
|
|
22
|
+
newContent = content.slice(0, metaStartInContent) + content.slice(metaEndInContent);
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
const pageMetaMatch = content.match(/<page-meta\b[^>]*>[\s\S]*?<\/page-meta>/);
|
|
26
|
+
if (pageMetaMatch) {
|
|
27
|
+
pageMetaSource = pageMetaMatch[0];
|
|
28
|
+
newContent = content.replace(pageMetaMatch[0], "");
|
|
29
|
+
} else {
|
|
30
|
+
const selfClosingMatch = content.match(/<page-meta\b[^>]*\/>/);
|
|
31
|
+
if (selfClosingMatch) {
|
|
32
|
+
pageMetaSource = selfClosingMatch[0];
|
|
33
|
+
newContent = content.replace(selfClosingMatch[0], "");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
24
36
|
}
|
|
25
37
|
const wrappedContent = `
|
|
26
38
|
${pageMetaSource}
|
|
27
39
|
<global-root-view>${newContent}</global-root-view>
|
|
28
40
|
`;
|
|
29
41
|
return {
|
|
30
|
-
code: code.slice(0, openTagEnd) + wrappedContent + code.slice(closeTagStart)
|
|
42
|
+
code: code.slice(0, openTagEnd) + wrappedContent + code.slice(closeTagStart),
|
|
43
|
+
map: {
|
|
44
|
+
version: 3,
|
|
45
|
+
sources: [],
|
|
46
|
+
names: [],
|
|
47
|
+
mappings: ""
|
|
48
|
+
}
|
|
31
49
|
};
|
|
32
50
|
}
|
|
33
51
|
export {
|
|
@@ -21,6 +21,14 @@ __export(root_exports, {
|
|
|
21
21
|
registerRootApp: () => registerRootApp
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(root_exports);
|
|
24
|
+
function createEmptySourcemap() {
|
|
25
|
+
return {
|
|
26
|
+
version: 3,
|
|
27
|
+
sources: [],
|
|
28
|
+
names: [],
|
|
29
|
+
mappings: ""
|
|
30
|
+
};
|
|
31
|
+
}
|
|
24
32
|
function registerRootApp(code, fileName = "App.root") {
|
|
25
33
|
const importCode = `import GlobalRootView from "./${fileName}.vue";`;
|
|
26
34
|
const vueUseComponentCode = `app.component("global-root-view", GlobalRootView);`;
|
|
@@ -33,10 +41,10 @@ function registerRootApp(code, fileName = "App.root") {
|
|
|
33
41
|
newCode = newCode.replace(/(createApp[\s\S]*?)(return\s*\{)/, `$1${vueUseComponentCode}
|
|
34
42
|
$2`);
|
|
35
43
|
}
|
|
36
|
-
return { code: newCode };
|
|
44
|
+
return { code: newCode, map: createEmptySourcemap() };
|
|
37
45
|
}
|
|
38
46
|
function rebuildRootApp(code) {
|
|
39
|
-
return { code };
|
|
47
|
+
return { code, map: createEmptySourcemap() };
|
|
40
48
|
}
|
|
41
49
|
// Annotate the CommonJS export names for ESM import in node:
|
|
42
50
|
0 && (module.exports = {
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
function createEmptySourcemap() {
|
|
2
|
+
return {
|
|
3
|
+
version: 3,
|
|
4
|
+
sources: [],
|
|
5
|
+
names: [],
|
|
6
|
+
mappings: ""
|
|
7
|
+
};
|
|
8
|
+
}
|
|
1
9
|
function registerRootApp(code, fileName = "App.root") {
|
|
2
10
|
const importCode = `import GlobalRootView from "./${fileName}.vue";`;
|
|
3
11
|
const vueUseComponentCode = `app.component("global-root-view", GlobalRootView);`;
|
|
@@ -10,10 +18,10 @@ function registerRootApp(code, fileName = "App.root") {
|
|
|
10
18
|
newCode = newCode.replace(/(createApp[\s\S]*?)(return\s*\{)/, `$1${vueUseComponentCode}
|
|
11
19
|
$2`);
|
|
12
20
|
}
|
|
13
|
-
return { code: newCode };
|
|
21
|
+
return { code: newCode, map: createEmptySourcemap() };
|
|
14
22
|
}
|
|
15
23
|
function rebuildRootApp(code) {
|
|
16
|
-
return { code };
|
|
24
|
+
return { code, map: createEmptySourcemap() };
|
|
17
25
|
}
|
|
18
26
|
export {
|
|
19
27
|
rebuildRootApp,
|
|
@@ -46,7 +46,7 @@ async function parseSFC(code) {
|
|
|
46
46
|
const { parse } = await import("vue/compiler-sfc");
|
|
47
47
|
return parse(code, { pad: "space" }).descriptor;
|
|
48
48
|
} catch {
|
|
49
|
-
|
|
49
|
+
return null;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
function stripJsonComments(str) {
|
|
@@ -6,7 +6,7 @@ async function parseSFC(code) {
|
|
|
6
6
|
const { parse } = await import("vue/compiler-sfc");
|
|
7
7
|
return parse(code, { pad: "space" }).descriptor;
|
|
8
8
|
} catch {
|
|
9
|
-
|
|
9
|
+
return null;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
function stripJsonComments(str) {
|