@aiot-toolkit/aiotpack 2.1.0-prender.7 → 2.1.0-prenderv1.1
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/lib/afterCompile/ux/UxAfterCompile.d.ts +4 -0
- package/lib/afterCompile/ux/UxAfterCompile.js +72 -12
- package/lib/compiler/javascript/JavascriptCompiler.js +15 -11
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +17 -4
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +1 -10
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +57 -241
- package/lib/compiler/javascript/vela/utils/Jsc.d.ts +3 -3
- package/lib/compiler/javascript/vela/utils/Jsc.js +4 -87
- package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +0 -9
- package/lib/compiler/javascript/vela/utils/ZipUtil.js +6 -112
- package/lib/config/UxConfig.js +3 -0
- package/lib/prerender/PrerenderVM.d.ts +79 -0
- package/lib/prerender/PrerenderVM.js +695 -0
- package/lib/prerender/StyleSerializer.d.ts +18 -0
- package/lib/prerender/StyleSerializer.js +92 -0
- package/lib/prerender/TemplateSerializer.d.ts +26 -0
- package/lib/prerender/TemplateSerializer.js +103 -0
- package/lib/prerender/index.d.ts +20 -0
- package/lib/prerender/index.js +225 -0
- package/lib/prerender/interface/IPrerenderOption.d.ts +15 -0
- package/lib/prerender/interface/IPrerenderOption.js +1 -0
- package/lib/utils/ux/UxLoaderUtils.js +3 -8
- package/package.json +6 -10
- package/lib/compiler/javascript/TemplateCompiler.d.ts +0 -19
- package/lib/compiler/javascript/TemplateCompiler.js +0 -685
- package/lib/compiler/javascript/ViteCompiler.d.ts +0 -17
- package/lib/compiler/javascript/ViteCompiler.js +0 -648
- package/lib/compiler/javascript/vela/utils/VruUtil.d.ts +0 -50
- package/lib/compiler/javascript/vela/utils/VruUtil.js +0 -128
|
@@ -6,6 +6,10 @@ import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavas
|
|
|
6
6
|
declare class UxAfterCompile {
|
|
7
7
|
static compileJavascript: FollowWork<IJavascriptCompileOption>;
|
|
8
8
|
static protobuf: FollowWork<IJavascriptCompileOption>;
|
|
9
|
+
/**
|
|
10
|
+
* 预渲染:在 VM 沙箱中执行编译后的模板函数,生成 .template.json + .css.json
|
|
11
|
+
*/
|
|
12
|
+
static prerender: FollowWork<IJavascriptCompileOption>;
|
|
9
13
|
static jsc: FollowWork<IJavascriptCompileOption>;
|
|
10
14
|
static toRpk: FollowWork<IJavascriptCompileOption>;
|
|
11
15
|
/**
|
|
@@ -9,7 +9,7 @@ var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
|
9
9
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
11
|
var _CompileMode = _interopRequireDefault(require("../../compiler/enum/CompileMode"));
|
|
12
|
-
var
|
|
12
|
+
var _JavascriptCompiler = _interopRequireDefault(require("../../compiler/javascript/JavascriptCompiler"));
|
|
13
13
|
var _JavascriptDefaultCompileOption = _interopRequireDefault(require("../../compiler/javascript/JavascriptDefaultCompileOption"));
|
|
14
14
|
var _Jsc = _interopRequireDefault(require("../../compiler/javascript/vela/utils/Jsc"));
|
|
15
15
|
var _ZipUtil = _interopRequireDefault(require("../../compiler/javascript/vela/utils/ZipUtil"));
|
|
@@ -19,6 +19,7 @@ var _ZipFileUtil = _interopRequireDefault(require("@aiot-toolkit/shared-utils/li
|
|
|
19
19
|
var _ImageIcu = _interopRequireDefault(require("../../compiler/tools/icu/ImageIcu"));
|
|
20
20
|
var _LiteCard = _interopRequireDefault(require("../../compiler/javascript/vela/utils/LiteCard"));
|
|
21
21
|
var _UxUtil = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/utils/UxUtil"));
|
|
22
|
+
var _prerender = require("../../prerender");
|
|
22
23
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
23
24
|
const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
|
|
24
25
|
|
|
@@ -32,7 +33,7 @@ class UxAfterCompile {
|
|
|
32
33
|
compilerOption,
|
|
33
34
|
onLog
|
|
34
35
|
} = params;
|
|
35
|
-
return new
|
|
36
|
+
return new _JavascriptCompiler.default(context, onLog).compile({
|
|
36
37
|
projectPath: _path.default.join(context.projectPath, context.output),
|
|
37
38
|
mode: _CompileMode.default.DEVELOPMENT,
|
|
38
39
|
devtool: false,
|
|
@@ -44,16 +45,11 @@ class UxAfterCompile {
|
|
|
44
45
|
level: _sharedUtils.Loglevel.SUCCESS,
|
|
45
46
|
message: ['javascript compile success']
|
|
46
47
|
}]);
|
|
47
|
-
}).catch(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
level: _sharedUtils.Loglevel.THROW,
|
|
53
|
-
message: [`javascript compile failed: ${err?.message ?? err}`]
|
|
54
|
-
}]);
|
|
55
|
-
throw err instanceof Error ? err : new Error(String(err));
|
|
56
|
-
}
|
|
48
|
+
}).catch(_ref => {
|
|
49
|
+
let {
|
|
50
|
+
errors,
|
|
51
|
+
warnings
|
|
52
|
+
} = _ref;
|
|
57
53
|
const errorLength = errors?.length || 0;
|
|
58
54
|
const messages = [`webpack error:\r\n`];
|
|
59
55
|
if (errors?.length) {
|
|
@@ -94,6 +90,70 @@ class UxAfterCompile {
|
|
|
94
90
|
BinaryPlugin.createBinFiles();
|
|
95
91
|
}
|
|
96
92
|
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 预渲染:在 VM 沙箱中执行编译后的模板函数,生成 .template.json + .css.json
|
|
96
|
+
*/
|
|
97
|
+
static prerender = async params => {
|
|
98
|
+
const {
|
|
99
|
+
compilerOption,
|
|
100
|
+
onLog,
|
|
101
|
+
compilation
|
|
102
|
+
} = params;
|
|
103
|
+
if (!compilerOption || compilerOption.enablePrerender === false) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// In watch mode, clear prerender caches for changed pages
|
|
108
|
+
if (compilation && compilation.trigger !== _FileLaneTriggerType.default.START) {
|
|
109
|
+
const {
|
|
110
|
+
sourceRoot
|
|
111
|
+
} = compilerOption;
|
|
112
|
+
const srcPath = _path.default.join(compilerOption.projectPath, sourceRoot);
|
|
113
|
+
const changedPages = (compilation.changedFiles || []).filter(f => compilation.entries?.includes(f)).map(f => {
|
|
114
|
+
const rel = _path.default.relative(srcPath, f).replace(/\\/g, '/');
|
|
115
|
+
return rel.replace(/\.[^.]+$/, '');
|
|
116
|
+
});
|
|
117
|
+
(0, _prerender.watchChange)(changedPages.length > 0 ? changedPages : undefined);
|
|
118
|
+
}
|
|
119
|
+
const {
|
|
120
|
+
projectPath,
|
|
121
|
+
outputPath,
|
|
122
|
+
sourceRoot
|
|
123
|
+
} = compilerOption;
|
|
124
|
+
const buildPath = _path.default.join(projectPath, outputPath);
|
|
125
|
+
const manifestPath = _path.default.join(projectPath, sourceRoot, 'manifest.json');
|
|
126
|
+
if (!_fsExtra.default.existsSync(manifestPath)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const excludeList = compilerOption.prerenderExclude || [];
|
|
130
|
+
const manifest = _fsExtra.default.readJSONSync(manifestPath);
|
|
131
|
+
const pages = Object.keys(manifest.router?.pages || {}).filter(pageName => {
|
|
132
|
+
if (excludeList.some(pattern => pageName.startsWith(pattern))) {
|
|
133
|
+
onLog?.([{
|
|
134
|
+
level: _sharedUtils.Loglevel.INFO,
|
|
135
|
+
message: [`prerender: skip excluded ${pageName}`]
|
|
136
|
+
}]);
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
}).map(pageName => {
|
|
141
|
+
const pageConf = manifest.router.pages[pageName];
|
|
142
|
+
const component = pageConf.component || 'index';
|
|
143
|
+
return `${pageName}/${component}`;
|
|
144
|
+
});
|
|
145
|
+
if (!pages.length) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const deviceTypes = manifest.deviceTypeList?.length ? manifest.deviceTypeList : ['default'];
|
|
149
|
+
await (0, _prerender.prerender)({
|
|
150
|
+
buildPath,
|
|
151
|
+
sourcePath: _path.default.join(projectPath, sourceRoot),
|
|
152
|
+
pages,
|
|
153
|
+
prerenderSubComp: compilerOption.prerenderSubComp !== false,
|
|
154
|
+
deviceTypes
|
|
155
|
+
}, onLog);
|
|
156
|
+
};
|
|
97
157
|
static jsc = async params => {
|
|
98
158
|
const {
|
|
99
159
|
context,
|
|
@@ -135,16 +135,12 @@ class JavascriptCompiler {
|
|
|
135
135
|
let result = {
|
|
136
136
|
context: projectPath,
|
|
137
137
|
mode,
|
|
138
|
-
devtool: devtool
|
|
138
|
+
devtool: devtool,
|
|
139
139
|
output: {
|
|
140
|
-
globalObject: '
|
|
140
|
+
globalObject: 'window',
|
|
141
141
|
filename: '[name].js',
|
|
142
142
|
publicPath: './',
|
|
143
|
-
path: buildPath
|
|
144
|
-
iife: false,
|
|
145
|
-
library: {
|
|
146
|
-
type: 'commonjs2'
|
|
147
|
-
}
|
|
143
|
+
path: buildPath
|
|
148
144
|
},
|
|
149
145
|
module: {
|
|
150
146
|
rules: [{
|
|
@@ -182,10 +178,7 @@ class JavascriptCompiler {
|
|
|
182
178
|
},
|
|
183
179
|
optimization: {
|
|
184
180
|
minimize: true,
|
|
185
|
-
minimizer: [this.createMinimizerRspackPlugin(param)]
|
|
186
|
-
splitChunks: false,
|
|
187
|
-
runtimeChunk: false,
|
|
188
|
-
concatenateModules: true
|
|
181
|
+
minimizer: [this.createMinimizerRspackPlugin(param)]
|
|
189
182
|
},
|
|
190
183
|
resolve: {
|
|
191
184
|
extensions: ['.js', '.ts', '.ux']
|
|
@@ -239,6 +232,17 @@ class JavascriptCompiler {
|
|
|
239
232
|
if (quickAppConfig?.postHook) {
|
|
240
233
|
quickAppConfig.postHook(result);
|
|
241
234
|
}
|
|
235
|
+
|
|
236
|
+
// 项目的 quickapp.config.js 可能 push 了 webpack 的插件实例(如 webpack.DefinePlugin),
|
|
237
|
+
// 这些实例与 rspack 不兼容。将已知可转换的插件替换为 rspack 等价实现。
|
|
238
|
+
if (Array.isArray(result.plugins)) {
|
|
239
|
+
result.plugins = result.plugins.map(plugin => {
|
|
240
|
+
if (plugin && plugin.constructor?.name === 'DefinePlugin' && plugin.definitions && !(plugin instanceof _core.rspack.DefinePlugin)) {
|
|
241
|
+
return new _core.rspack.DefinePlugin(plugin.definitions);
|
|
242
|
+
}
|
|
243
|
+
return plugin;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
242
246
|
return result;
|
|
243
247
|
}
|
|
244
248
|
getConfigurator(param) {
|
|
@@ -40,10 +40,6 @@ interface IJavascriptCompileOption extends ICompileParam {
|
|
|
40
40
|
* 禁用 jsc
|
|
41
41
|
*/
|
|
42
42
|
enableJsc?: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* 启用 VRU 包装格式(release 模式生成 manifest+CERT+inner-vru 的双层 RPK)
|
|
45
|
-
*/
|
|
46
|
-
enableVru?: boolean;
|
|
47
43
|
/**
|
|
48
44
|
* 启用 protobuf
|
|
49
45
|
*/
|
|
@@ -80,6 +76,23 @@ interface IJavascriptCompileOption extends ICompileParam {
|
|
|
80
76
|
* @example log,warn
|
|
81
77
|
*/
|
|
82
78
|
dropConsole?: boolean | string;
|
|
79
|
+
/**
|
|
80
|
+
* 启用预渲染
|
|
81
|
+
*
|
|
82
|
+
* 编译后在 VM 沙箱中执行模板函数,生成 .template.json + .css.json
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
enablePrerender?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* 是否预渲染子组件(import 引用的组件)
|
|
88
|
+
* @default true
|
|
89
|
+
*/
|
|
90
|
+
prerenderSubComp?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* 排除不预渲染的页面路径列表
|
|
93
|
+
* 支持前缀匹配,如 ['pages/Dynamic'] 会排除 pages/Dynamic/index 等
|
|
94
|
+
*/
|
|
95
|
+
prerenderExclude?: string[];
|
|
83
96
|
/**
|
|
84
97
|
* 启动页
|
|
85
98
|
*/
|
|
@@ -4,16 +4,7 @@ declare class WrapPlugin {
|
|
|
4
4
|
private compilerOption;
|
|
5
5
|
constructor(compilerOption: IJavascriptCompileOption);
|
|
6
6
|
apply(compiler: Compiler): void;
|
|
7
|
-
private getComponentName;
|
|
8
|
-
private findMatching;
|
|
9
|
-
/**
|
|
10
|
-
* Extract keyed modules from rspack's __webpack_modules__ object
|
|
11
|
-
*/
|
|
12
|
-
private extractModules;
|
|
13
|
-
/**
|
|
14
|
-
* Clean a module body into blueos-pack format component block
|
|
15
|
-
*/
|
|
16
|
-
private buildBlock;
|
|
17
7
|
private wrap;
|
|
8
|
+
private translateStyleFunc;
|
|
18
9
|
}
|
|
19
10
|
export default WrapPlugin;
|
|
@@ -5,265 +5,81 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _core = require("@rspack/core");
|
|
8
|
-
var _TemplateCompiler = require("../../TemplateCompiler");
|
|
9
8
|
var _webpackSources = require("webpack-sources");
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
9
|
class WrapPlugin {
|
|
13
10
|
constructor(compilerOption) {
|
|
14
11
|
this.compilerOption = compilerOption;
|
|
15
12
|
}
|
|
16
13
|
apply(compiler) {
|
|
14
|
+
// 给入口文件加上包裹函数
|
|
17
15
|
compiler.hooks.compilation.tap('WrapPlugin', compilation => {
|
|
18
16
|
compilation.hooks.processAssets.tap({
|
|
19
17
|
name: 'WrapPlugin',
|
|
20
18
|
stage: _core.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
|
|
21
|
-
}, () =>
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
getComponentName(entry) {
|
|
25
|
-
return _path.default.parse(entry).name;
|
|
26
|
-
}
|
|
27
|
-
findMatching(code, start, open, close) {
|
|
28
|
-
let depth = 0,
|
|
29
|
-
inStr = null,
|
|
30
|
-
esc = false;
|
|
31
|
-
for (let i = start; i < code.length; i++) {
|
|
32
|
-
const ch = code[i];
|
|
33
|
-
if (esc) {
|
|
34
|
-
esc = false;
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (ch === '\\') {
|
|
38
|
-
esc = true;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (inStr) {
|
|
42
|
-
if (ch === inStr) inStr = null;
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
if (ch === '"' || ch === "'" || ch === '`') {
|
|
46
|
-
inStr = ch;
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (ch === open) depth++;else if (ch === close) {
|
|
50
|
-
depth--;
|
|
51
|
-
if (depth === 0) return i;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return -1;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Extract keyed modules from rspack's __webpack_modules__ object
|
|
58
|
-
*/
|
|
59
|
-
extractModules(code) {
|
|
60
|
-
const idx = code.indexOf('var __webpack_modules__');
|
|
61
|
-
if (idx === -1) return [{
|
|
62
|
-
key: '',
|
|
63
|
-
body: code
|
|
64
|
-
}];
|
|
65
|
-
const braceIdx = code.indexOf('{', idx + 23);
|
|
66
|
-
let openIdx = code.indexOf('(', idx + 23);
|
|
67
|
-
if (openIdx === -1 || braceIdx !== -1 && braceIdx < openIdx) openIdx = braceIdx;
|
|
68
|
-
if (openIdx === -1) return [{
|
|
69
|
-
key: '',
|
|
70
|
-
body: code
|
|
71
|
-
}];
|
|
72
|
-
const closeIdx = code[openIdx] === '(' ? this.findMatching(code, openIdx, '(', ')') : this.findMatching(code, openIdx, '{', '}');
|
|
73
|
-
if (closeIdx === -1) return [{
|
|
74
|
-
key: '',
|
|
75
|
-
body: code
|
|
76
|
-
}];
|
|
77
|
-
const inner = code.slice(openIdx + 1, closeIdx);
|
|
78
|
-
const results = [];
|
|
79
|
-
let pos = 0;
|
|
80
|
-
while (pos < inner.length) {
|
|
81
|
-
const kStart = inner.indexOf('"', pos);
|
|
82
|
-
if (kStart === -1) break;
|
|
83
|
-
const kEnd = inner.indexOf('"', kStart + 1);
|
|
84
|
-
if (kEnd === -1) break;
|
|
85
|
-
const key = inner.slice(kStart + 1, kEnd);
|
|
86
|
-
pos = kEnd + 1;
|
|
87
|
-
const fIdx = inner.indexOf('function', pos);
|
|
88
|
-
if (fIdx === -1) break;
|
|
89
|
-
const bOpen = inner.indexOf('{', fIdx);
|
|
90
|
-
if (bOpen === -1) break;
|
|
91
|
-
const bClose = this.findMatching(inner, bOpen, '{', '}');
|
|
92
|
-
if (bClose === -1) break;
|
|
93
|
-
results.push({
|
|
94
|
-
key,
|
|
95
|
-
body: inner.slice(bOpen + 1, bClose).trim()
|
|
19
|
+
}, () => {
|
|
20
|
+
this.wrap(compilation);
|
|
96
21
|
});
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
return results.length > 0 ? results : [{
|
|
100
|
-
key: '',
|
|
101
|
-
body: code
|
|
102
|
-
}];
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Clean a module body into blueos-pack format component block
|
|
106
|
-
*/
|
|
107
|
-
buildBlock(body, defineId, styleId) {
|
|
108
|
-
let s = body;
|
|
109
|
-
// Remove ALL _interopRequireDefault function definitions FIRST (before unwrapping calls)
|
|
110
|
-
while (true) {
|
|
111
|
-
const iIdx = s.indexOf('function _interopRequireDefault');
|
|
112
|
-
if (iIdx === -1) break;
|
|
113
|
-
const bStart = s.indexOf('{', iIdx);
|
|
114
|
-
if (bStart === -1) break;
|
|
115
|
-
const bEnd = this.findMatching(s, bStart, '{', '}');
|
|
116
|
-
if (bEnd === -1) break;
|
|
117
|
-
s = s.slice(0, iIdx) + s.slice(bEnd + 1);
|
|
118
|
-
}
|
|
119
|
-
// Then unwrap _interopRequireDefault() calls
|
|
120
|
-
const interopVars = [];
|
|
121
|
-
s = s.replace(/_interopRequireDefault\(([^)]+)\)/g, (_, inner) => inner);
|
|
122
|
-
// Remove .default from interop vars
|
|
123
|
-
for (const v of interopVars) {
|
|
124
|
-
s = s.replace(new RegExp(`${v}\\.default\\.`, 'g'), `${v}.`);
|
|
125
|
-
s = s.replace(new RegExp(`${v}\\.default([^.]|$)`, 'g'), `${v}$1`);
|
|
126
|
-
}
|
|
127
|
-
// Remove boilerplate
|
|
128
|
-
// Replace $app_style$ array with @info reference using unique per-component name
|
|
129
|
-
const styleIdx = s.indexOf('var $app_style$');
|
|
130
|
-
if (styleIdx !== -1) {
|
|
131
|
-
const bi = s.indexOf('[', styleIdx);
|
|
132
|
-
if (bi !== -1) {
|
|
133
|
-
const be = this.findMatching(s, bi, '[', ']');
|
|
134
|
-
if (be !== -1) {
|
|
135
|
-
let se = s.indexOf(';', be);
|
|
136
|
-
if (se === -1) se = be;
|
|
137
|
-
// Remove the entire var $app_style$ line (we use $app_style$<id> instead)
|
|
138
|
-
s = s.slice(0, styleIdx) + s.slice(se + 1);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// Also remove any remaining var $app_style$ = {...} (already @info format)
|
|
143
|
-
s = s.replace(/var \$app_style\$\s*=[^;]*;\s*/g, '');
|
|
144
|
-
s = s.replace(/module\.exports[^;]*;\s*/g, '');
|
|
145
|
-
// Preserve $app_template$ for prerender (will be stripped after template.json is generated)
|
|
146
|
-
let templateCode = '';
|
|
147
|
-
const tplIdx = body.indexOf('var $app_template$');
|
|
148
|
-
if (tplIdx !== -1) {
|
|
149
|
-
const fnStart = body.indexOf('function', tplIdx);
|
|
150
|
-
if (fnStart !== -1) {
|
|
151
|
-
const braceStart = body.indexOf('{', fnStart);
|
|
152
|
-
if (braceStart !== -1) {
|
|
153
|
-
const braceEnd = this.findMatching(body, braceStart, '{', '}');
|
|
154
|
-
if (braceEnd !== -1) {
|
|
155
|
-
templateCode = body.slice(tplIdx, braceEnd + 1) + ';';
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
s = s.replace(/\$app_exports\$\[[^\]]*\][^;]*;\s*/g, '');
|
|
161
|
-
s = s.replace(/var \$app_exports\$[^;]*;\s*/g, '');
|
|
162
|
-
s = s.replace(/\$app_exports\$\.default[^;]*;\s*/g, '');
|
|
163
|
-
s = s.replace(/"use strict";\s*/g, '');
|
|
164
|
-
s = s.replace(/Object\.defineProperty\(exports,\s*"__esModule"[^;]*;\s*/g, '');
|
|
165
|
-
s = s.replace(/exports\["default"\]\s*=\s*void 0;\s*/g, '');
|
|
166
|
-
s = s.replace(/const moduleOwn[\s\S]*?}\s*}\s*}\s*/g, '');
|
|
167
|
-
s = s.replace(/var exports\s*=\s*module\.exports;\s*/g, '');
|
|
168
|
-
// Remove __webpack_require__ calls (including the var declaration if present)
|
|
169
|
-
s = s.replace(/(?:var|const|let)\s+\w+\s*=\s*__webpack_require__\([^)]*\);?\s*/g, '');
|
|
170
|
-
s = s.replace(/__webpack_require__\([^)]*\);?\s*/g, '');
|
|
171
|
-
// Extract component object
|
|
172
|
-
let obj = '{}';
|
|
173
|
-
const m = s.match(/(?:var _default\s*=\s*)?exports\["default"\]\s*=\s*(\{[\s\S]*\}|[\w.]+);?\s*$/);
|
|
174
|
-
if (m) {
|
|
175
|
-
obj = m[1];
|
|
176
|
-
s = s.slice(0, s.indexOf(m[0])).trim();
|
|
177
|
-
}
|
|
178
|
-
const lines = [`let $style$${styleId} = {"@info":{"styleObjectId":${styleId}}};`, `const $app_style$${styleId} = $style$${styleId};`, ...(s.trim() ? [s.trim()] : []), ...(templateCode ? [templateCode] : []), `const $app_script$${styleId} = ${obj};`, `$app_define$("${defineId}", [], function($app_require$, $app_exports$, $app_module$) {`, ` $app_module$.exports = $app_script$${styleId}.default || $app_script$${styleId};`, ` $app_module$.exports.style = $app_style$${styleId};`, ...(templateCode ? [` $app_module$.exports.template = $app_template$;`] : []), `});`];
|
|
179
|
-
return lines.join('\n');
|
|
22
|
+
});
|
|
180
23
|
}
|
|
181
24
|
wrap(compilation) {
|
|
25
|
+
const {
|
|
26
|
+
enableE2e
|
|
27
|
+
} = this.compilerOption;
|
|
28
|
+
// 获取入口文件
|
|
182
29
|
const entrys = Object.keys(compilation.options.entry).map(item => `${item}.js`);
|
|
30
|
+
// 从chunk找到所有入口文件,添加包裹函数
|
|
183
31
|
entrys.forEach(entry => {
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const be = this.findMatching(mod.body, bi, '[', ']');
|
|
198
|
-
if (be === -1) continue;
|
|
199
|
-
try {
|
|
200
|
-
const styleStr = mod.body.slice(bi, be + 1);
|
|
201
|
-
const sid = (0, _TemplateCompiler.getStyleObjectId)(mod.key || entry);
|
|
202
|
-
const cssObj = (0, _TemplateCompiler.parseStyleArray)(styleStr);
|
|
203
|
-
if (Object.keys(cssObj).length > 0) cssJsonData[String(sid)] = cssObj;
|
|
204
|
-
} catch {}
|
|
205
|
-
}
|
|
206
|
-
const cssJsonPath = entry.replace(/\.js$/, '.css.json');
|
|
207
|
-
compilation.assets[cssJsonPath] = new _webpackSources.RawSource(JSON.stringify(cssJsonData, null, 2));
|
|
208
|
-
// Emit component import map for template.json generation
|
|
209
|
-
const importMap = {};
|
|
210
|
-
for (const mod of modules) {
|
|
211
|
-
if (!mod.key.includes('?uxType=') && mod.key !== '' && mod.key.endsWith('.ux')) {
|
|
212
|
-
const entryM = modules.find(m => m.key.includes('?uxType=') || m.key === '');
|
|
213
|
-
const escaped = mod.key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
214
|
-
const nm = entryM?.body.match(new RegExp(`\\$app_exports\\$\\['([^']+)'\\]\\s*=\\s*__webpack_require__\\([^)]*"${escaped}"\\)`));
|
|
215
|
-
const name = nm ? nm[1] : _path.default.parse(mod.key.replace(/\.ux$/, '')).name.toLowerCase();
|
|
216
|
-
// Convert "./src/components/Card.ux" to "components/Card"
|
|
217
|
-
const importPath = mod.key.replace(/^\.\/src\//, '').replace(/\.ux$/, '');
|
|
218
|
-
importMap[name] = importPath;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (Object.keys(importMap).length > 0) {
|
|
222
|
-
const mapPath = entry.replace(/\.js$/, '.imports.json');
|
|
223
|
-
compilation.assets[mapPath] = new _webpackSources.RawSource(JSON.stringify(importMap));
|
|
224
|
-
}
|
|
225
|
-
const blocks = [];
|
|
226
|
-
// Find entry module to extract component name mappings
|
|
227
|
-
const entryMod = modules.find(m => m.key.includes('?uxType=') || m.key === '');
|
|
228
|
-
for (const mod of modules) {
|
|
229
|
-
// Check if this entry has non-.ux JS dependencies
|
|
230
|
-
const hasJsDeps = modules.some(m => m.key && !m.key.endsWith('.ux') && !m.key.includes('?uxType=') && m.key !== '' && !m.key.endsWith('.json'));
|
|
32
|
+
if (compilation.assets[entry]) {
|
|
33
|
+
const source = compilation.assets[entry];
|
|
34
|
+
const isApp = entry === 'app.js';
|
|
35
|
+
const createFuncnName = isApp ? 'createAppHandler' : 'createPageHandler';
|
|
36
|
+
compilation.assets[entry] = new _webpackSources.ConcatSource(`export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
|
|
37
|
+
var org_app_require = $app_require$;
|
|
38
|
+
|
|
39
|
+
(function(global, globalThis, window, $app_exports$, $app_evaluate$){
|
|
40
|
+
var setTimeout = global.setTimeout;
|
|
41
|
+
var setInterval = global.setInterval;
|
|
42
|
+
var clearTimeout = global.clearTimeout;
|
|
43
|
+
var clearInterval = global.clearInterval;
|
|
44
|
+
var $app_require$ = global.$app_require$ || org_app_require
|
|
231
45
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
blocks.push(`var exports = $app_module$.exports;`);
|
|
241
|
-
blocks.push(`var module = $app_module$;`);
|
|
242
|
-
blocks.push(sourceCode);
|
|
243
|
-
blocks.push(`$app_module$.exports.style = $app_style$${styleId};`);
|
|
244
|
-
blocks.push(`});`);
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
// Non-.ux modules (utility JS files) are handled by webpack runtime above
|
|
248
|
-
if (mod.key && !mod.key.endsWith('.ux') && !mod.key.includes('?uxType=') && mod.key !== '') {
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
let compName;
|
|
252
|
-
if (mod.key.includes('?uxType=') || mod.key === '') {
|
|
253
|
-
compName = componentName;
|
|
254
|
-
} else {
|
|
255
|
-
// Find component name from: $app_exports$['name'] = __webpack_require__(/*...*/ "key")
|
|
256
|
-
const escaped = mod.key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
257
|
-
const nm = entryMod?.body.match(new RegExp(`\\$app_exports\\$\\['([^']+)'\\]\\s*=\\s*__webpack_require__\\([^)]*"${escaped}"\\)`));
|
|
258
|
-
compName = nm ? nm[1] : _path.default.parse(mod.key.replace(/\.ux$/, '')).name.toLowerCase();
|
|
259
|
-
}
|
|
260
|
-
const defineId = isApp && mod === entryMod ? '@app-component/app' : `@app-component/${compName}`;
|
|
261
|
-
const styleId = (0, _TemplateCompiler.getStyleObjectId)(mod.key || entry);
|
|
262
|
-
blocks.push(this.buildBlock(mod.body, defineId, styleId));
|
|
46
|
+
${enableE2e ? `globalThis = undefined; \n global = typeof window === "undefined" ? global.__proto__ : window;` : ''}
|
|
47
|
+
var ${createFuncnName} = function() {
|
|
48
|
+
return `, source, `
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return ${createFuncnName}();
|
|
52
|
+
})(global, globalThis, window, $app_exports$, $app_evaluate$)
|
|
53
|
+
}`);
|
|
263
54
|
}
|
|
264
|
-
blocks.push(`$app_bootstrap$("${bootstrapId}");`);
|
|
265
|
-
compilation.assets[entry] = new _webpackSources.RawSource(blocks.join('\n') + '\n');
|
|
266
55
|
});
|
|
267
56
|
}
|
|
57
|
+
translateStyleFunc() {
|
|
58
|
+
return `
|
|
59
|
+
var $translateStyle$ = function (value) {
|
|
60
|
+
if (typeof value === 'string') {
|
|
61
|
+
return Object.fromEntries(
|
|
62
|
+
value
|
|
63
|
+
.split(';')
|
|
64
|
+
.filter((item) => Boolean(item && item.trim()))
|
|
65
|
+
.map((item) => {
|
|
66
|
+
const matchs = item.match(/([^:]+):(.*)/);
|
|
67
|
+
if (matchs && matchs.length > 2) {
|
|
68
|
+
return [
|
|
69
|
+
matchs[1]
|
|
70
|
+
.trim()
|
|
71
|
+
.replace(/-([a-z])/g, (_, match) => match.toUpperCase()),
|
|
72
|
+
matchs[2].trim(),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
return [];
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
};
|
|
81
|
+
global.$translateStyle$ = $translateStyle$
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
268
84
|
}
|
|
269
85
|
var _default = exports.default = WrapPlugin;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jsc
|
|
3
|
+
*/
|
|
1
4
|
declare class Jsc {
|
|
2
5
|
readonly projectPath: string;
|
|
3
6
|
readonly buildPath: string;
|
|
4
7
|
constructor(projectPath: string, buildPath: string);
|
|
5
8
|
jsc(deleteJs?: boolean): Promise<boolean>;
|
|
6
|
-
private logBeforeInvoke;
|
|
7
|
-
private logAfterInvoke;
|
|
8
|
-
private static listFiles;
|
|
9
9
|
}
|
|
10
10
|
export default Jsc;
|