@proteus-vue/plugin-vite 0.2.0-beta.0 → 0.2.0-beta.4
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/LICENSE +218 -0
- package/README.md +38 -0
- package/dist/appSkeleton.d.ts +1 -1
- package/dist/cache.d.ts +6 -0
- package/dist/devtools-plugin.d.ts +35 -0
- package/dist/devtools-relay.d.ts +19 -0
- package/dist/gen-routes.d.ts +9 -4
- package/dist/index.d.ts +9 -1
- package/dist/index.js +1708 -654
- package/dist/plugin.d.ts +75 -7
- package/dist/resolve-components.d.ts +10 -0
- package/dist/tag-scan.d.ts +28 -0
- package/dist/vite-config.d.ts +20 -0
- package/package.json +14 -12
package/dist/plugin.d.ts
CHANGED
|
@@ -1,18 +1,63 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
+
import type { VariantPlatform } from '@proteus-vue/compiler';
|
|
2
3
|
import type { TransformRuleOverrides } from '@proteus-vue/compiler';
|
|
3
4
|
import type { ProteusConfig } from './config';
|
|
5
|
+
/** ★MP 专用原生标签(Web 端无对等):位于组件模板的**平台死分支**(`v-if="!isWeb"`)时不渲染,
|
|
6
|
+
* 但 Vue 会把 `resolveComponent` 提升到 render 顶部 → Web 端仍会解析失败告警。
|
|
7
|
+
* 在 @vitejs/plugin-vue 的 `isCustomElement` 里声明为自定义元素即消除(见 vite-config.ts)。 */
|
|
8
|
+
export declare const MP_ONLY_TAGS: Set<string>;
|
|
4
9
|
export declare function defaultScopedPlugin(): Plugin;
|
|
5
10
|
export declare function resolvePkgPath(projectRoot: string, modPath: string): string;
|
|
11
|
+
/** ★平台变体·CSS(2026-09-13,第 5 层):`<style src="./theme.css">` 加载并按目标平台解析变体。
|
|
12
|
+
* `./theme.css` → 存在 theme.mp.css 则用它(否则 theme.css)。相对引用方 .vue 所在目录解析。 */
|
|
13
|
+
export declare function loadStyleSrcWithVariant(src: string, fromFilename: string, platform?: VariantPlatform): string | null;
|
|
6
14
|
/**
|
|
7
15
|
* ★module-plan B0 + platform-plan B5 尾:共享模块解析(纯函数可测)
|
|
8
16
|
* - 相对路径(本地 .ts/.js)→ 产物相对 appDir 路径
|
|
9
17
|
* - @proteus-vue/*(框架包 dist)→ 产物 _proteus/<name>(白名单放行;微信 require 缓存同路径同实例)
|
|
10
18
|
* - 其余裸模块(vue/pinia 等第三方)→ null(不参与)
|
|
11
19
|
*/
|
|
12
|
-
|
|
20
|
+
/** ★vendor 单例清单(2026-09-12 真机 bug 修复):这些库含模块级可变状态
|
|
21
|
+
* (pinia 的 activePinia / vue 的 currentInstance),若各 bundle 内联 → 多份独立实例 →
|
|
22
|
+
* setActivePinia 设的那份不是 useStore() 查的那份 → store 全失效。故统一 external 到 `_proteus/<name>.js`。
|
|
23
|
+
* @vue/devtools-api 是 pinia 的运行时依赖,同样单例化(避免多份注册表)。 */
|
|
24
|
+
export declare const VENDOR_SINGLETONS: string[];
|
|
25
|
+
export declare function resolveSharedModule(appDir: string, absFrom: string, source: string, frameworkDir?: string,
|
|
26
|
+
/** 解析基准目录(真实构建传 projectRoot):@proteus-vue/* 从项目 node_modules 解析。
|
|
27
|
+
* 缺省回退 plugin 自身位置——★真机 bug 修复 2026-09-12:此前恒用模块级 require(plugin 位置),
|
|
28
|
+
* pnpm 严格链接下 @proteus-vue/{api,runtime,desktop,capabilities,app-config,shared}(应用声明、非 plugin 依赖)
|
|
29
|
+
* 解析失败 → 返回 null → 这些 _proteus/*.js 从不产出,而页面产物却 require 它们(onLoad 崩溃)。 */
|
|
30
|
+
resolveFrom?: string,
|
|
31
|
+
/** ★平台变体解析目标(2026-09-13):相对导入优先命中 foo.<platform>.ts(缺省 mp) */
|
|
32
|
+
platform?: VariantPlatform): {
|
|
13
33
|
file: string;
|
|
14
34
|
relNoExt: string;
|
|
15
35
|
} | null;
|
|
36
|
+
/**
|
|
37
|
+
* ★共享模块 import 扫描(module-plan B0):返回源码中的 import 源模块(纯函数可测)
|
|
38
|
+
* ★2026-09-07 修复:多行 named import(import {\n a,\n} from 'x')此前漏扫(正则 .*? 无 s 标志不跨行)→
|
|
39
|
+
* @proteus-vue/desktop 等跨行 import 不进共享模块 → 页面产物丢 require → 运行时 ReferenceError 白屏
|
|
40
|
+
* 实现:\s\s(等价 s 标志)跨行 + 量词限制在「{…}」或标识符内(防 from 后源串含 from 字符串误切——源串仅取引号内)
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* ★全局样式选择器改写(app.wxss 通道,2026-09-12):
|
|
44
|
+
* 源文件写标准 CSS(`:root`),小程序 WXSS 的根选择器是 `page`——WXSS 不支持 `:root`
|
|
45
|
+
* (微信告警且不生效 → 设计 token 全失效)。构建期把 `:root` 改写为 `page`,保持单一事实源。
|
|
46
|
+
* 纯函数可测。仅在规则位置(行首/`}`/`,`/空白后)匹配 `:root`,避免误伤字符串/选择器内部。
|
|
47
|
+
*/
|
|
48
|
+
export declare function rewriteRootToPage(css: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* ★2026-09-08 reactivity-runtime spke:把产物 JS 里的裸 `require('@proteus-vue/<x>')` 映射为相对 `_proteus/<x>.js`。
|
|
51
|
+
* 编译器注入的 reactivity require(以及任何编译器内联的框架包 require)是裸行,不经过 moduleImports 的 import 改写;
|
|
52
|
+
* MP 运行时无 miniprogram_npm,必须相对 require 到 _proteus/ 共享产物(微信 require 缓存同路径同实例)。
|
|
53
|
+
* relOutputPath = 产物输出路径无扩展名(如 pages/foo);`_proteus/<x>.js` 在 appDir 顶层。
|
|
54
|
+
* 纯函数可测。
|
|
55
|
+
*/
|
|
56
|
+
export declare function rewriteFrameworkRequires(js: string, relOutput: string): string;
|
|
57
|
+
export declare function scanSourceImports(source: string): Array<{
|
|
58
|
+
source: string;
|
|
59
|
+
typeOnly: boolean;
|
|
60
|
+
}>;
|
|
16
61
|
/**
|
|
17
62
|
* 提取 builder 函数名:function xxxBuilder(...)
|
|
18
63
|
*/
|
|
@@ -29,7 +74,7 @@ export declare function assembleAppJs(mainCode: string, presets: Array<{
|
|
|
29
74
|
name: string;
|
|
30
75
|
fnName: string;
|
|
31
76
|
source: string;
|
|
32
|
-
}
|
|
77
|
+
}>, piniaInstall?: string): string;
|
|
33
78
|
/**
|
|
34
79
|
* 过滤被开发者覆盖的预设:main 中已 addRouteBuilder('<name>' 的预设跳过自动注册(开发者优先)
|
|
35
80
|
*/
|
|
@@ -51,11 +96,34 @@ export interface PluginOptions {
|
|
|
51
96
|
/** ★底线循环 ①③:规则覆盖(缺省取 config.rules) */
|
|
52
97
|
rules?: TransformRuleOverrides;
|
|
53
98
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* 缺省相对工程根 src/components(create-proteus 模板工程用)
|
|
57
|
-
* ★v2.0 退役:@proteus-vue/components 拆为独立 npm 包后本选项删除(改 resolvePkgPath 包内路径,见 docs/packages.md)
|
|
99
|
+
* ★语义组件库目录(@proteus-vue/components,2026-09-14 拆包):**通常无需传入**——
|
|
100
|
+
* 自动从项目 node_modules 解析包根(`resolveComponentsRoot`);仅用于包未安装时的显式覆盖(测试)。
|
|
58
101
|
*/
|
|
59
|
-
|
|
102
|
+
componentsDir?: string;
|
|
60
103
|
}
|
|
104
|
+
/** ★2026-09-13:MP 待编译清单收集(页面 vs 组件分类的**唯一权威**处)。
|
|
105
|
+
* 分类依据 = **文件来自哪个源目录**,而不是「路径里有没有 components 字样」:
|
|
106
|
+
* 分包目录名常叫 components(如 subpackages/components/pages/*),旧启发式
|
|
107
|
+
* `file.includes('/components/')` 会把**页面**误判为组件 → 产物成 Component() 且跳过
|
|
108
|
+
* 页面滚动容器包装 → 组件详情页整页无法滚动(首页正常,因其路径不含 components)。
|
|
109
|
+
* 组件仅来自两处(与 gen-routes 解析口径一致):<appDir>/components 与 @proteus-vue/components 包。 */
|
|
110
|
+
export declare function collectMpEntries(opts: {
|
|
111
|
+
projectRoot: string;
|
|
112
|
+
appDir: string;
|
|
113
|
+
pagesDir: string;
|
|
114
|
+
subPackages: Array<{
|
|
115
|
+
root: string;
|
|
116
|
+
}>;
|
|
117
|
+
componentsDir: string;
|
|
118
|
+
webOnlyPages?: Set<string>;
|
|
119
|
+
onSkipWebOnly?: (file: string) => void;
|
|
120
|
+
/** ★平台变体(2026-09-13):按该平台解析 `foo.mp.vue`/`foo.web.vue`(缺省 mp) */
|
|
121
|
+
platform?: VariantPlatform;
|
|
122
|
+
/** ★框架组件输出策略(2026-09-18):'used'(缺省,按引用闭包输出)/ 'all'(全量,逃生舱) */
|
|
123
|
+
componentEmit?: 'used' | 'all';
|
|
124
|
+
}): Array<{
|
|
125
|
+
file: string;
|
|
126
|
+
rel: string;
|
|
127
|
+
isComponent: boolean;
|
|
128
|
+
}>;
|
|
61
129
|
export default function mpTransform(opts: PluginOptions): Plugin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** 语义组件库包名 */
|
|
2
|
+
export declare const COMPONENTS_PKG = "@proteus-vue/components";
|
|
3
|
+
/**
|
|
4
|
+
* 解析 `@proteus-vue/components` 的**包根**绝对路径(含 .vue 源码的目录)。
|
|
5
|
+
* 解析顺序:① projectRoot/node_modules 真实解析(createRequire)→ ② 回退 projectRoot/node_modules/<pkg>(软链)
|
|
6
|
+
* → ③ 兜底返回路径本身(调用方负责 existsSync 判断 + 告警)。
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveComponentsRoot(projectRoot: string): string;
|
|
9
|
+
/** 判断组件库是否可解析(供 plugin 在无 p-* 场景下静默跳过) */
|
|
10
|
+
export declare function componentsRootExists(projectRoot: string): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** 抽取 `<template>` 块正文(跳过注释 / script / style / 嵌套 template 深度) */
|
|
2
|
+
export declare function extractTemplateBody(src: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* 扫描模板正文中出现的全部标签名(kebab 化;跳过注释块)。
|
|
5
|
+
* PascalCase(`<PSafe>`)→ kebab(`p-safe`)——★旧正则只匹配小写开头,
|
|
6
|
+
* 导致 `<PSafe>` 完全跳过扫描(既不注册也不告警 → 组件静默不渲染,showcase 踩坑)。
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractTags(tpl: string): Set<string>;
|
|
9
|
+
/**
|
|
10
|
+
* ★编译器**产出**的组件标签(源码模板中不存在,由 compiler lowering 生成)。
|
|
11
|
+
* 必须计入引用集合,否则按需输出会把这些组件漏掉 → 运行时不渲染(真 bug)。
|
|
12
|
+
*
|
|
13
|
+
* 与 gen-routes 的 collectComponents 同源规则(两处必须一致):
|
|
14
|
+
* 源码含**形状变化动画**的 SVG(cx/r/d/stroke-dashoffset 等)→ 编译器 lowering 为 `<p-svg-canvas>`。
|
|
15
|
+
*/
|
|
16
|
+
export declare function collectCompilerEmittedTags(templateBody: string): Set<string>;
|
|
17
|
+
/**
|
|
18
|
+
* 计算页面**实际引用**的框架组件目录集合(含组件间传递依赖闭包)。
|
|
19
|
+
*
|
|
20
|
+
* 用途:MP 产物只输出用到的组件(而非全量 76 个 = 607 KB)——对每个真实应用都是可观瘦身。
|
|
21
|
+
* ★诚实边界:仅识别**静态模板标签**。运行时动态拼标签不受支持(MP 本就无 `<component :is>`,
|
|
22
|
+
* 编译器已对 `<component :is>` 显式告警)——若确有非常规用法,可用 `components.emit: 'all'` 关闭本优化。
|
|
23
|
+
*
|
|
24
|
+
* @param pageFiles 页面源文件绝对路径(主包 + 分包,**须已排除 webOnly 页面**)
|
|
25
|
+
* @param componentsDir 框架组件根目录
|
|
26
|
+
* @returns 组件目录名集合(如 `p-view`);空集表示「未引用任何框架组件」
|
|
27
|
+
*/
|
|
28
|
+
export declare function collectUsedFrameworkComponents(pageFiles: readonly string[], componentsDir: string): Set<string>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { InlineConfig } from 'vite';
|
|
2
|
+
import type { ProteusConfig } from '@proteus-vue/types';
|
|
3
|
+
export interface ProteusViteContext {
|
|
4
|
+
/** 工程根(proteus.config.ts 所在目录) */
|
|
5
|
+
root: string;
|
|
6
|
+
/** serve(dev server)| build */
|
|
7
|
+
command: 'serve' | 'build';
|
|
8
|
+
/** vite mode:web / mp-weixin */
|
|
9
|
+
mode: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ProteusViteResult {
|
|
12
|
+
/** 标准 vite InlineConfig(可直接喂 createServer / build) */
|
|
13
|
+
config: InlineConfig;
|
|
14
|
+
/** mp 目标:是否需要先跑 gen-routes(CLI 在 vite 启动前执行) */
|
|
15
|
+
needsGenRoutes: boolean;
|
|
16
|
+
/** mp 目标:是否有 mp-entry(虚拟模块由框架插件直出 app.js 骨架) */
|
|
17
|
+
platform: 'web' | 'mp-weixin';
|
|
18
|
+
}
|
|
19
|
+
/** 组装框架 vite 配置(纯异步:vue 插件从工程 node_modules 动态解析) */
|
|
20
|
+
export declare function resolveProteusViteConfig(ctx: ProteusViteContext, config: ProteusConfig): Promise<ProteusViteResult>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteus-vue/plugin-vite",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.4",
|
|
4
4
|
"description": "Proteus Vite 插件(mp-weixin 编译管线适配层)+ gen-routes 路由表生成器",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -18,23 +18,25 @@
|
|
|
18
18
|
"dist",
|
|
19
19
|
"README.md"
|
|
20
20
|
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"prepare": "npm run build",
|
|
23
|
-
"build": "tsc -p tsconfig.build.json --emitDeclarationOnly && esbuild src/index.ts --bundle --format=esm --platform=node --outfile=dist/index.js --external:@proteus-vue/compiler --external:@proteus-vue/router --external:esbuild --external:sass --external:vite"
|
|
24
|
-
},
|
|
25
21
|
"dependencies": {
|
|
26
|
-
"@proteus-vue/compiler": "0.3.0-beta.
|
|
27
|
-
"@proteus-vue/module": "0.1.0",
|
|
28
|
-
"@proteus-vue/router": "0.2.0-beta.
|
|
29
|
-
"@proteus-vue/types": "0.
|
|
22
|
+
"@proteus-vue/compiler": "0.3.0-beta.3",
|
|
23
|
+
"@proteus-vue/module": "0.1.1-beta.0",
|
|
24
|
+
"@proteus-vue/router": "0.2.0-beta.4",
|
|
25
|
+
"@proteus-vue/types": "0.2.0-beta.2",
|
|
30
26
|
"esbuild": "^0.28.2",
|
|
31
|
-
"sass": "^1.103.1"
|
|
27
|
+
"sass": "^1.103.1",
|
|
28
|
+
"ws": "^8.0.0",
|
|
29
|
+
"@proteus-vue/compiler-backend": "0.1.1-beta.1"
|
|
32
30
|
},
|
|
33
31
|
"peerDependencies": {
|
|
34
32
|
"vite": "^5.0.0"
|
|
35
33
|
},
|
|
36
34
|
"devDependencies": {
|
|
37
35
|
"@types/node": "^20.0.0",
|
|
38
|
-
"vite": "^5.0.0"
|
|
36
|
+
"vite": "^5.0.0",
|
|
37
|
+
"@types/ws": "^8.18.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.build.json --emitDeclarationOnly && esbuild src/index.ts --bundle --format=esm --platform=node --outfile=dist/index.js --external:@proteus-vue/compiler-backend --external:@proteus-vue/compiler --external:@proteus-vue/router --external:esbuild --external:sass --external:vite --external:ws"
|
|
39
41
|
}
|
|
40
|
-
}
|
|
42
|
+
}
|