@dongmingzhixiu/vuexir 0.3.1 → 0.3.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/dist/bundle.d.ts +13 -0
- package/dist/bundle.js +53 -0
- package/dist/gen-ios.js +12 -2
- package/package.json +3 -3
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface BundleResult {
|
|
2
|
+
/** IIFE 代码(空串表示没有可打包的 util) */
|
|
3
|
+
code: string;
|
|
4
|
+
/** 成功打包的文件名 */
|
|
5
|
+
included: string[];
|
|
6
|
+
/** 跳过的文件(含原因) */
|
|
7
|
+
skipped: {
|
|
8
|
+
file: string;
|
|
9
|
+
reason: string;
|
|
10
|
+
}[];
|
|
11
|
+
}
|
|
12
|
+
/** 打包 src/utils 下可独立运行的 util(`@/types` 等纯类型导入会被 esbuild 擦除) */
|
|
13
|
+
export declare function bundleProjectUtils(projectRoot: string): BundleResult;
|
package/dist/bundle.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* R97 P2:把工程里的**纯逻辑 util** 用 esbuild 打成 IIFE bundle,
|
|
3
|
+
* 供原生 JS 运行时(iOS JavaScriptCore / Android QuickJS)在页面脚本之前加载。
|
|
4
|
+
*
|
|
5
|
+
* 目的:`computed(() => countChars(raw))` 这类引用了 utils 的表达式,
|
|
6
|
+
* 过去只能跳过(原生端没有这些函数);打包后函数成为全局,表达式可直接求值。
|
|
7
|
+
*
|
|
8
|
+
* 策略:逐个文件尝试打包,**失败的(依赖 dexie / DOM / 浏览器 API)自动跳过**并返回告警,
|
|
9
|
+
* 保证「能打的都打上,打不了的明确说明」,不静默。
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { buildSync } from 'esbuild';
|
|
14
|
+
/** 打包 src/utils 下可独立运行的 util(`@/types` 等纯类型导入会被 esbuild 擦除) */
|
|
15
|
+
export function bundleProjectUtils(projectRoot) {
|
|
16
|
+
const utilsDir = join(projectRoot, 'src', 'utils');
|
|
17
|
+
if (!existsSync(utilsDir))
|
|
18
|
+
return { code: '', included: [], skipped: [] };
|
|
19
|
+
const included = [];
|
|
20
|
+
const skipped = [];
|
|
21
|
+
const chunks = [];
|
|
22
|
+
for (const file of readdirSync(utilsDir)) {
|
|
23
|
+
if (!/\.(ts|js|mts)$/.test(file) || file.endsWith('.d.ts'))
|
|
24
|
+
continue;
|
|
25
|
+
try {
|
|
26
|
+
const out = buildSync({
|
|
27
|
+
entryPoints: [join(utilsDir, file)],
|
|
28
|
+
bundle: true,
|
|
29
|
+
write: false,
|
|
30
|
+
format: 'iife',
|
|
31
|
+
// 每个文件一个独立命名空间,避免后一个 IIFE 覆盖前一个的导出
|
|
32
|
+
globalName: `__vrnUtils_${included.length}`,
|
|
33
|
+
platform: 'neutral',
|
|
34
|
+
target: 'es2019',
|
|
35
|
+
// 纯类型导入会被擦除;若确实依赖运行期外部包(dexie 等)则整包失败 → 跳过该文件
|
|
36
|
+
external: [],
|
|
37
|
+
logLevel: 'silent',
|
|
38
|
+
alias: { '@': join(projectRoot, 'src') },
|
|
39
|
+
});
|
|
40
|
+
const code = out.outputFiles?.[0]?.text ?? '';
|
|
41
|
+
if (code) {
|
|
42
|
+
// 导出提升为全局:模板表达式里是裸调用(countChars(...)),必须能在全局找到
|
|
43
|
+
chunks.push(code +
|
|
44
|
+
`\n;(function(){var m=__vrnUtils_${included.length};if(!m)return;for(var k in m){try{if(typeof globalThis[k]==='undefined')globalThis[k]=m[k];}catch(e){}}})();`);
|
|
45
|
+
included.push(file);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
skipped.push({ file, reason: e.message.split('\n')[0]?.slice(0, 120) ?? '打包失败' });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { code: chunks.join('\n'), included, skipped };
|
|
53
|
+
}
|
package/dist/gen-ios.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, statSync, copyFileSync, rmSync } from 'node:fs';
|
|
16
16
|
import { basename, dirname, join } from 'node:path';
|
|
17
17
|
import { fileURLToPath } from 'node:url';
|
|
18
|
+
import { bundleProjectUtils } from './bundle.js';
|
|
18
19
|
import { TEMPLATE_VERSION, VRN_BRIDGE_SWIFT, projectYml as PROJECT_YML, templateFiles } from '@dongmingzhixiu/vuexir-templates';
|
|
19
20
|
import { parseRouter as parseRouterV2, findProjectRoot } from '@dongmingzhixiu/vuexir-compiler';
|
|
20
21
|
import { validateIr } from '@dongmingzhixiu/vuexir-compiler';
|
|
@@ -661,6 +662,15 @@ function runTabs(appDir, opts = {}) {
|
|
|
661
662
|
// 写前清空源目录:删除页面后残留的旧 View/runtime 仍会进 Xcode 工程(幽灵页面)
|
|
662
663
|
rmSync(srcDir, { recursive: true, force: true });
|
|
663
664
|
mkdirSync(srcDir, { recursive: true });
|
|
665
|
+
// R97 P2:把可独立运行的 utils 打成 IIFE,前置到每个页面 runtime 之前,
|
|
666
|
+
// 让 computed 里引用的外部函数(countChars / normalize …)在原生 JS 运行时可用
|
|
667
|
+
const utilsBundle = bundleProjectUtils(findProjectRoot(appDir));
|
|
668
|
+
if (utilsBundle.included.length > 0) {
|
|
669
|
+
console.log(`[gen-ios] utils bundle: ${utilsBundle.included.join(', ')}`);
|
|
670
|
+
}
|
|
671
|
+
for (const sk of utilsBundle.skipped) {
|
|
672
|
+
console.log(`[gen-ios] utils bundle 跳过 ${sk.file}:${sk.reason}`);
|
|
673
|
+
}
|
|
664
674
|
const allUis = [];
|
|
665
675
|
const pageFiles = [];
|
|
666
676
|
const pageRuntimes = [];
|
|
@@ -703,7 +713,7 @@ function runTabs(appDir, opts = {}) {
|
|
|
703
713
|
for (const w of genWarnings)
|
|
704
714
|
console.log(`[gen-ios] 生成提示(${tab.id},tab 页): ${w}`);
|
|
705
715
|
writeFileSync(join(srcDir, `${pageId}View.swift`), swift);
|
|
706
|
-
writeFileSync(join(srcDir, `runtime_${pageId}.js`), r.runtime ?? '');
|
|
716
|
+
writeFileSync(join(srcDir, `runtime_${pageId}.js`), utilsBundle.code + '\n' + (r.runtime ?? ''));
|
|
707
717
|
pageFiles.push(`${pageId}View.swift`);
|
|
708
718
|
pageRuntimes.push({ id: pageId, src: r.runtime ?? '' });
|
|
709
719
|
pageStates.push({
|
|
@@ -761,7 +771,7 @@ function runTabs(appDir, opts = {}) {
|
|
|
761
771
|
for (const w of genWarnings)
|
|
762
772
|
console.log(`[gen-ios] 生成提示(${d.id},push 页): ${w}`);
|
|
763
773
|
writeFileSync(join(srcDir, viewFile), swift);
|
|
764
|
-
writeFileSync(join(srcDir, `runtime_${pageId}Detail.js`), r.runtime ?? '');
|
|
774
|
+
writeFileSync(join(srcDir, `runtime_${pageId}Detail.js`), utilsBundle.code + '\n' + (r.runtime ?? ''));
|
|
765
775
|
pageFiles.push(viewFile);
|
|
766
776
|
pageRuntimes.push({ id: `${pageId}Detail`, src: r.runtime ?? '' });
|
|
767
777
|
detailPages.push({ id: d.id, title: d.title, view: viewName, path: d.path });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dongmingzhixiu/vuexir",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "vrn 命令行:build ios|android、preview、doctor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"LICENSE"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@dongmingzhixiu/vuexir-compiler": "^0.3.
|
|
25
|
-
"@dongmingzhixiu/vuexir-templates": "^0.3.
|
|
24
|
+
"@dongmingzhixiu/vuexir-compiler": "^0.3.3",
|
|
25
|
+
"@dongmingzhixiu/vuexir-templates": "^0.3.3"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": ">=18"
|