@aiot-toolkit/aiotpack 2.0.6-beta.8 → 2.1.0-prender.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 +90 -2
- package/lib/compiler/javascript/JavascriptCompiler.js +11 -4
- package/lib/compiler/javascript/TemplateCompiler.d.ts +29 -0
- package/lib/compiler/javascript/TemplateCompiler.js +564 -0
- package/lib/compiler/javascript/ViteCompiler.d.ts +13 -0
- package/lib/compiler/javascript/ViteCompiler.js +414 -0
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +26 -0
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +3 -1
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +16 -1
- package/lib/compiler/javascript/vela/interface/IManifest.d.ts +12 -0
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +10 -1
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +241 -57
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.d.ts +3 -2
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +12 -4
- package/lib/compiler/javascript/vela/utils/VruUtil.d.ts +50 -0
- package/lib/compiler/javascript/vela/utils/VruUtil.js +128 -0
- package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +9 -0
- package/lib/compiler/javascript/vela/utils/ZipUtil.js +112 -6
- package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackJsLoader.js +1 -1
- package/lib/config/UxConfig.d.ts +12 -5
- package/lib/config/UxConfig.js +7 -6
- package/lib/loader/ux/JsLoader.d.ts +9 -0
- package/lib/loader/ux/JsLoader.js +47 -8
- package/lib/loader/ux/vela/HmlLoader.d.ts +6 -6
- package/lib/loader/ux/vela/HmlLoader.js +30 -13
- package/lib/prerender/PrerenderVM.d.ts +86 -0
- package/lib/prerender/PrerenderVM.js +677 -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 +122 -0
- package/lib/prerender/index.d.ts +20 -0
- package/lib/prerender/index.js +519 -0
- package/lib/prerender/interface/IPrerenderOption.d.ts +15 -0
- package/lib/prerender/interface/IPrerenderOption.js +1 -0
- package/lib/utils/BeforeCompileUtils.d.ts +1 -1
- package/lib/utils/BeforeCompileUtils.js +52 -9
- package/lib/utils/ux/ManifestSchema.js +0 -1
- package/lib/utils/ux/UxFileUtils.js +1 -1
- package/lib/utils/ux/UxLoaderUtils.d.ts +6 -0
- package/lib/utils/ux/UxLoaderUtils.js +22 -10
- package/package.json +9 -6
|
@@ -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 _ViteCompiler = _interopRequireDefault(require("../../compiler/javascript/ViteCompiler"));
|
|
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"));
|
|
@@ -18,6 +18,8 @@ var _FileLaneTriggerType = _interopRequireDefault(require("file-lane/lib/enum/Fi
|
|
|
18
18
|
var _ZipFileUtil = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/utils/ZipFileUtil"));
|
|
19
19
|
var _ImageIcu = _interopRequireDefault(require("../../compiler/tools/icu/ImageIcu"));
|
|
20
20
|
var _LiteCard = _interopRequireDefault(require("../../compiler/javascript/vela/utils/LiteCard"));
|
|
21
|
+
var _UxUtil = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/utils/UxUtil"));
|
|
22
|
+
var _prerender = require("../../prerender");
|
|
21
23
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
24
|
const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
|
|
23
25
|
|
|
@@ -31,7 +33,7 @@ class UxAfterCompile {
|
|
|
31
33
|
compilerOption,
|
|
32
34
|
onLog
|
|
33
35
|
} = params;
|
|
34
|
-
return new
|
|
36
|
+
return new _ViteCompiler.default(context, onLog).compile({
|
|
35
37
|
projectPath: _path.default.join(context.projectPath, context.output),
|
|
36
38
|
mode: _CompileMode.default.DEVELOPMENT,
|
|
37
39
|
devtool: false,
|
|
@@ -88,6 +90,70 @@ class UxAfterCompile {
|
|
|
88
90
|
BinaryPlugin.createBinFiles();
|
|
89
91
|
}
|
|
90
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
|
+
};
|
|
91
157
|
static jsc = async params => {
|
|
92
158
|
const {
|
|
93
159
|
context,
|
|
@@ -239,6 +305,28 @@ class UxAfterCompile {
|
|
|
239
305
|
});
|
|
240
306
|
}
|
|
241
307
|
}
|
|
308
|
+
|
|
309
|
+
// e2e
|
|
310
|
+
if (compilerOption.e2eConfigPath && compilerOption.enableE2e) {
|
|
311
|
+
const testConfig = _UxUtil.default.getE2eConfig({
|
|
312
|
+
projectPath: compilerOption.projectPath,
|
|
313
|
+
e2eConfigPath: compilerOption.e2eConfigPath
|
|
314
|
+
});
|
|
315
|
+
const testPagePath = _path.default.parse(_path.default.relative(_path.default.join(compilerOption.projectPath, sourceRoot), _path.default.join(testConfig.dir, testConfig.entry.path)).replaceAll(_path.default.sep, _path.default.posix.sep));
|
|
316
|
+
// 1. 修改entry
|
|
317
|
+
const entryName = testPagePath.dir;
|
|
318
|
+
const launchMode = testConfig.entry?.launchMode;
|
|
319
|
+
if (entryName) {
|
|
320
|
+
content.router.entry = entryName;
|
|
321
|
+
}
|
|
322
|
+
// 2. 添加测试页到router.pages
|
|
323
|
+
if (content.router.pages) {
|
|
324
|
+
content.router.pages[entryName] = {
|
|
325
|
+
component: testPagePath.name,
|
|
326
|
+
launchMode
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
}
|
|
242
330
|
_fsExtra.default.writeJSONSync(_path.default.join(projectPath, outputPath, _UxFileUtils.default.CONFIG_FILE_NAME), content, {
|
|
243
331
|
spaces: 2
|
|
244
332
|
});
|
|
@@ -135,12 +135,16 @@ class JavascriptCompiler {
|
|
|
135
135
|
let result = {
|
|
136
136
|
context: projectPath,
|
|
137
137
|
mode,
|
|
138
|
-
devtool: devtool,
|
|
138
|
+
devtool: devtool || false,
|
|
139
139
|
output: {
|
|
140
|
-
globalObject: '
|
|
140
|
+
globalObject: 'global',
|
|
141
141
|
filename: '[name].js',
|
|
142
142
|
publicPath: './',
|
|
143
|
-
path: buildPath
|
|
143
|
+
path: buildPath,
|
|
144
|
+
iife: false,
|
|
145
|
+
library: {
|
|
146
|
+
type: 'commonjs2'
|
|
147
|
+
}
|
|
144
148
|
},
|
|
145
149
|
module: {
|
|
146
150
|
rules: [{
|
|
@@ -178,7 +182,10 @@ class JavascriptCompiler {
|
|
|
178
182
|
},
|
|
179
183
|
optimization: {
|
|
180
184
|
minimize: true,
|
|
181
|
-
minimizer: [this.createMinimizerRspackPlugin(param)]
|
|
185
|
+
minimizer: [this.createMinimizerRspackPlugin(param)],
|
|
186
|
+
splitChunks: false,
|
|
187
|
+
runtimeChunk: false,
|
|
188
|
+
concatenateModules: true
|
|
182
189
|
},
|
|
183
190
|
resolve: {
|
|
184
191
|
extensions: ['.js', '.ts', '.ux']
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare function uxToTemplateJson(templateNode: any, styleObjectId?: number, styleSheet?: any, importMap?: Record<string, string>, pageDir?: string): any;
|
|
2
|
+
/**
|
|
3
|
+
* Normalize a media query condition text from CSS Level 4 syntax to Level 3.
|
|
4
|
+
*
|
|
5
|
+
* Level 4 → Level 3:
|
|
6
|
+
* `(width <= 30)` → `(max-width: 30)`
|
|
7
|
+
* `(width >= 80)` → `(min-width: 80)`
|
|
8
|
+
* `(400 <= width <= 700)` → `(min-width: 400) and (max-width: 700)`
|
|
9
|
+
* `(width < 30)` → `(max-width: 29)` // strict → off-by-one
|
|
10
|
+
* Same for height/aspect-ratio. Other features pass through.
|
|
11
|
+
*
|
|
12
|
+
* `screen and ` is preserved; `not` / `only` are preserved as-is.
|
|
13
|
+
*/
|
|
14
|
+
declare function normalizeMediaQuery(condition: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Parse compiled $app_style$ array. Each rule is either:
|
|
17
|
+
* [selectors, props] — base rule
|
|
18
|
+
* [{condition: "<media-query>"}, selectors, props] — conditional rule (@media or @import with query)
|
|
19
|
+
*
|
|
20
|
+
* Returns a flat map: selectors → props for base rules, plus
|
|
21
|
+
* `"@media <normalizedConditionText>"` keys whose values are the per-condition
|
|
22
|
+
* `{selector: props}` map. The condition text is normalized to Level 3 so
|
|
23
|
+
* runtime only needs a Level-3 matcher.
|
|
24
|
+
*/
|
|
25
|
+
declare function parseStyleArray(code: string): Record<string, any>;
|
|
26
|
+
/** Convert CSS text to css.json format */
|
|
27
|
+
export { uxToTemplateJson, parseStyleArray, normalizeMediaQuery };
|
|
28
|
+
/** Compute styleObjectId hash from a string (same algorithm as blueos-pack) */
|
|
29
|
+
export declare function getStyleObjectId(name: string): number;
|