@aiot-toolkit/aiotpack 2.0.5-beta.2 → 2.0.5-beta.21

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.
Files changed (58) hide show
  1. package/lib/afterCompile/ux/UxAfterCompile.d.ts +28 -1
  2. package/lib/afterCompile/ux/UxAfterCompile.js +172 -17
  3. package/lib/afterWorks/ux/UxAfterWorks.js +1 -1
  4. package/lib/compiler/javascript/JavascriptCompiler.d.ts +14 -0
  5. package/lib/compiler/javascript/JavascriptCompiler.js +91 -5
  6. package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +21 -1
  7. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +5 -1
  8. package/lib/compiler/javascript/vela/interface/IManifest.d.ts +11 -0
  9. package/lib/compiler/javascript/vela/interface/IManifest.js +11 -1
  10. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +1 -4
  11. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +5 -0
  12. package/lib/compiler/javascript/vela/utils/webpackLoader/IWebpackLoaderOption.d.ts +11 -0
  13. package/lib/compiler/javascript/vela/utils/webpackLoader/IWebpackLoaderOption.js +1 -0
  14. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackJsLoader.d.ts +2 -0
  15. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackJsLoader.js +27 -0
  16. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackUxLoader.d.ts +2 -0
  17. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackUxLoader.js +26 -0
  18. package/lib/compiler/tools/icu/ImageIcu.d.ts +37 -0
  19. package/lib/compiler/tools/icu/ImageIcu.js +110 -0
  20. package/lib/compiler/tools/icu/icu_darwin_arm64 +0 -0
  21. package/lib/compiler/tools/icu/icu_darwin_x64 +0 -0
  22. package/lib/compiler/tools/icu/icu_linux_arm64 +0 -0
  23. package/lib/compiler/tools/icu/icu_linux_x64 +0 -0
  24. package/lib/compiler/tools/icu/icu_win32_x64.exe +0 -0
  25. package/lib/config/UxConfig.d.ts +5 -2
  26. package/lib/config/UxConfig.js +13 -2
  27. package/lib/index.d.ts +1 -3
  28. package/lib/index.js +2 -28
  29. package/lib/loader/ux/JsLoader.d.ts +1 -1
  30. package/lib/loader/ux/JsLoader.js +20 -17
  31. package/lib/loader/ux/vela/UxLoader.js +7 -0
  32. package/lib/utils/BeforeCompileUtils.d.ts +2 -0
  33. package/lib/utils/BeforeCompileUtils.js +25 -10
  34. package/lib/utils/ux/FileCompare.d.ts +12 -0
  35. package/lib/utils/ux/FileCompare.js +47 -0
  36. package/lib/utils/ux/ManifestSchema.js +6 -3
  37. package/lib/utils/ux/UxFileUtils.d.ts +11 -8
  38. package/lib/utils/ux/UxFileUtils.js +48 -27
  39. package/lib/utils/ux/UxLoaderUtils.js +28 -1
  40. package/package.json +9 -12
  41. package/lib/afterCompile/xts/entryTemplate.d.ts +0 -21
  42. package/lib/afterCompile/xts/entryTemplate.js +0 -182
  43. package/lib/afterCompile/xts/generateRpk.d.ts +0 -3
  44. package/lib/afterCompile/xts/generateRpk.js +0 -28
  45. package/lib/afterCompile/xts/ts2wasm.d.ts +0 -8
  46. package/lib/afterCompile/xts/ts2wasm.js +0 -69
  47. package/lib/beforeCompile/xts/preInstall.d.ts +0 -3
  48. package/lib/beforeCompile/xts/preInstall.js +0 -54
  49. package/lib/config/XtsConfig.d.ts +0 -22
  50. package/lib/config/XtsConfig.js +0 -36
  51. package/lib/interface/ICompileOptions.d.ts +0 -6
  52. package/lib/interface/ICompileOptions.js +0 -7
  53. package/lib/loader/xts/XtsLoader.d.ts +0 -9
  54. package/lib/loader/xts/XtsLoader.js +0 -62
  55. package/lib/utils/xts/XtsFileLaneUtils.d.ts +0 -10
  56. package/lib/utils/xts/XtsFileLaneUtils.js +0 -61
  57. package/lib/utils/xts/XtsFollowWorks.d.ts +0 -34
  58. package/lib/utils/xts/XtsFollowWorks.js +0 -134
@@ -4,7 +4,7 @@ import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavas
4
4
  * UxAfterCompile
5
5
  */
6
6
  declare class UxAfterCompile {
7
- static webpack: FollowWork<IJavascriptCompileOption>;
7
+ static compileJavascript: FollowWork<IJavascriptCompileOption>;
8
8
  static protobuf: FollowWork<IJavascriptCompileOption>;
9
9
  static jsc: FollowWork<IJavascriptCompileOption>;
10
10
  static toRpk: FollowWork<IJavascriptCompileOption>;
@@ -15,6 +15,13 @@ declare class UxAfterCompile {
15
15
  * @param compilerOption
16
16
  */
17
17
  static copyResource: FollowWork<IJavascriptCompileOption>;
18
+ /**
19
+ * 压缩资源文件
20
+ * 1. png8
21
+ * 2. bin
22
+ * @param params
23
+ */
24
+ static compressResource: FollowWork<IJavascriptCompileOption>;
18
25
  /**
19
26
  * 如果是更新触发,则对比临时项目build文件夹 和 项目build文件夹,生成diff.json
20
27
  * @param context
@@ -39,5 +46,25 @@ declare class UxAfterCompile {
39
46
  * @param compilerOption
40
47
  */
41
48
  static symlinkNodeModule: FollowWork<IJavascriptCompileOption>;
49
+ /**
50
+ * 编译轻卡ux
51
+ * 1. 使用hap-toolkit编译项目,编译结果存储在build文件夹
52
+ * 1.1 重写stdout以捕获hap-toolkit中的正常日志,错误日志正常输出
53
+ * 1.2 使用hap-toolkit编译项目
54
+ * 1.3 还原stdout
55
+ * 2. 取widgets中配置的轻卡内容,将build文件夹中对应的产物复制到临时文件夹
56
+ * @param params
57
+ */
58
+ static compileLiteCard: FollowWork<IJavascriptCompileOption>;
59
+ /**
60
+ * 检查资源文件
61
+ * 1. 检查文件体积是否过大, 如果超出,则提示到真机验证
62
+ * @param params
63
+ */
64
+ static resourceCheck: FollowWork<IJavascriptCompileOption>;
65
+ /**
66
+ * 写入.gitignore文件, 忽略临时目录
67
+ */
68
+ static writeGitIgnore: FollowWork<IJavascriptCompileOption>;
42
69
  }
43
70
  export default UxAfterCompile;
@@ -16,19 +16,23 @@ var _ZipUtil = _interopRequireDefault(require("../../compiler/javascript/vela/ut
16
16
  var _UxFileUtils = _interopRequireDefault(require("../../utils/ux/UxFileUtils"));
17
17
  var _FileLaneTriggerType = _interopRequireDefault(require("file-lane/lib/enum/FileLaneTriggerType"));
18
18
  var _ZipFileUtil = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/utils/ZipFileUtil"));
19
+ var _process = require("process");
20
+ var _ImageIcu = _interopRequireDefault(require("../../compiler/tools/icu/ImageIcu"));
19
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
22
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
23
+ const HapToolkit = require('hap-toolkit');
21
24
 
22
25
  /**
23
26
  * UxAfterCompile
24
27
  */
25
28
  class UxAfterCompile {
26
- static webpack = async params => {
29
+ static compileJavascript = async params => {
27
30
  const {
28
31
  context,
29
- compilerOption
32
+ compilerOption,
33
+ onLog
30
34
  } = params;
31
- return new _JavascriptCompiler.default().compile({
35
+ return new _JavascriptCompiler.default(context, onLog).compile({
32
36
  projectPath: _path.default.join(context.projectPath, context.output),
33
37
  mode: _CompileMode.default.DEVELOPMENT,
34
38
  devtool: false,
@@ -89,12 +93,12 @@ class UxAfterCompile {
89
93
  const {
90
94
  compilerOption,
91
95
  compalition,
92
- config
96
+ context
93
97
  } = params;
94
98
  if (compilerOption) {
95
99
  const fileName = await _ZipUtil.default.createRpk(_path.default.join(compilerOption.projectPath, compilerOption.outputPath), compilerOption);
96
100
  if (compalition && fileName) {
97
- compalition.info.rpk = _path.default.join(config.projectPath, compilerOption.releasePath, fileName);
101
+ compalition.info.rpk = _path.default.join(context.projectPath, compilerOption.releasePath, fileName);
98
102
  }
99
103
  return fileName;
100
104
  }
@@ -144,7 +148,7 @@ class UxAfterCompile {
144
148
  sourceRoot,
145
149
  outputPath
146
150
  } = compilerOption;
147
- const includeList = [/sitemap\.json$/, /i18n(.+)\.json/];
151
+ const includeList = [/sitemap\.json$/, /i18n(.+)\.json/, /web\/*/];
148
152
  const excludeExtList = ['js', 'jsx', 'coffee', 'ts', 'tsx', 'vue', 'css', 'less', 'sass', 'styl', 'html', 'md', 'ux', 'mix', 'DS_Store', 'map'];
149
153
  const excludeReg = `\\.(${excludeExtList.join('|')})$`;
150
154
  _sharedUtils.FileUtil.copyFiles(_path.default.join(projectPath, sourceRoot), _path.default.join(projectPath, outputPath), new RegExp(excludeReg));
@@ -162,7 +166,8 @@ class UxAfterCompile {
162
166
  projectPath,
163
167
  sourceRoot,
164
168
  outputPath,
165
- completeFeature
169
+ completeFeature,
170
+ startPage
166
171
  } = compilerOption;
167
172
  const content = _UxFileUtils.default.getManifestInfo(projectPath, sourceRoot);
168
173
  const translateCache = context.translateCache;
@@ -173,6 +178,15 @@ class UxAfterCompile {
173
178
  content.packageInfo = _ZipUtil.default.createComment(compilerOption);
174
179
  }
175
180
 
181
+ // 如果有startPage,且feature中没有router,则添加router
182
+ const routerFeature = 'system.router';
183
+ if (startPage && !content.features?.find(item => item.name === routerFeature)) {
184
+ content.features = content.features || [];
185
+ content.features.push({
186
+ name: routerFeature
187
+ });
188
+ }
189
+
176
190
  // feature
177
191
  if (translateCache?.featureCache.size) {
178
192
  // 消息提示
@@ -251,6 +265,37 @@ class UxAfterCompile {
251
265
  await genMetaFiles(compilerOption);
252
266
  }
253
267
  };
268
+
269
+ /**
270
+ * 压缩资源文件
271
+ * 1. png8
272
+ * 2. bin
273
+ * @param params
274
+ */
275
+ static compressResource = async params => {
276
+ const {
277
+ compilerOption
278
+ } = params;
279
+ if (compilerOption) {
280
+ const {
281
+ enableImagePng8,
282
+ projectPath,
283
+ outputPath
284
+ } = compilerOption;
285
+ if (enableImagePng8) {
286
+ const format = 'png';
287
+ const files = _sharedUtils.FileUtil.readAlldirSync(_path.default.join(projectPath, outputPath));
288
+ const compressFiles = files.filter(filePath => _ImageIcu.default.canTranslate(filePath, format));
289
+ if (compressFiles.length) {
290
+ const icu = new _ImageIcu.default();
291
+ compressFiles.forEach(item => {
292
+ icu.translate(item, _path.default.dirname(item), format);
293
+ });
294
+ }
295
+ }
296
+ }
297
+ };
298
+
254
299
  /**
255
300
  * 如果是更新触发,则对比临时项目build文件夹 和 项目build文件夹,生成diff.json
256
301
  * @param context
@@ -261,7 +306,7 @@ class UxAfterCompile {
261
306
  const {
262
307
  compilerOption,
263
308
  compalition,
264
- config
309
+ context
265
310
  } = params;
266
311
  if (!compilerOption || !compalition) {
267
312
  return;
@@ -269,19 +314,16 @@ class UxAfterCompile {
269
314
  if (compalition.trigger === _FileLaneTriggerType.default.START) {
270
315
  return;
271
316
  }
272
- const {
273
- outputPath,
274
- projectPath
275
- } = compilerOption;
276
317
  // 读取临时项目build文件夹中所有文件路径
277
- const tempBuildPath = _path.default.join(projectPath, outputPath);
318
+ const tempBuildDir = _path.default.join(compilerOption.projectPath, compilerOption.outputPath);
278
319
  // 待优化,map文件跟随源文件变化,与时间戳有关文件无需对比
279
- const tempFileList = _sharedUtils.FileUtil.readAlldirSync(tempBuildPath).map(filePath => _path.default.relative(tempBuildPath, filePath));
280
- const diffList = _UxFileUtils.default.getDiffJSON(compalition, tempFileList, tempBuildPath);
320
+ const tempFileList = _sharedUtils.FileUtil.readAlldirSync(tempBuildDir);
321
+ const buildDir = _path.default.join(context.projectPath, compilerOption.outputPath);
322
+ const diffList = _UxFileUtils.default.getDiffJSON(compalition.buildFileList, tempFileList, buildDir, tempBuildDir);
281
323
 
282
324
  // 所有差异文件,压缩到 .diff.rpk 中
283
325
  if (diffList?.length) {
284
- const buildFold = _path.default.join(compilerOption.projectPath, compilerOption.outputPath);
326
+ const buildFold = tempBuildDir;
285
327
  const distFold = _path.default.join(compilerOption.projectPath, compilerOption.releasePath);
286
328
  const diffFileName = `.diff.rpk`;
287
329
  const diffPath = _path.default.join(distFold, diffFileName);
@@ -290,7 +332,7 @@ class UxAfterCompile {
290
332
  zipFilePath: item
291
333
  })));
292
334
  compalition.info.diffList = diffList;
293
- compalition.info.diffFile = _path.default.join(config.projectPath, compilerOption.releasePath, diffFileName);
335
+ compalition.info.diffFile = _path.default.join(context.projectPath, compilerOption.releasePath, diffFileName);
294
336
  }
295
337
  };
296
338
 
@@ -361,5 +403,118 @@ class UxAfterCompile {
361
403
  throw new Error(`${error?.toString() || 'unknown error'}. Please check whether the file system of the current disk supports the creation of soft links.`);
362
404
  }
363
405
  };
406
+ /**
407
+ * 编译轻卡ux
408
+ * 1. 使用hap-toolkit编译项目,编译结果存储在build文件夹
409
+ * 1.1 重写stdout以捕获hap-toolkit中的正常日志,错误日志正常输出
410
+ * 1.2 使用hap-toolkit编译项目
411
+ * 1.3 还原stdout
412
+ * 2. 取widgets中配置的轻卡内容,将build文件夹中对应的产物复制到临时文件夹
413
+ * @param params
414
+ */
415
+ static compileLiteCard = async params => {
416
+ const {
417
+ compilerOption,
418
+ context
419
+ } = params;
420
+ try {
421
+ if (context?.liteCards?.length > 0 && compilerOption) {
422
+ const {
423
+ projectPath,
424
+ outputPath
425
+ } = compilerOption;
426
+ const LITE_OUTPUT_PATH = outputPath;
427
+ // 1.1
428
+ const originalStdout = _process.stdout.write;
429
+ _process.stdout.write = function () {
430
+ return true;
431
+ };
432
+ // 1.2
433
+ await HapToolkit.compile('native', 'dev', false, {
434
+ cwd: context.projectPath,
435
+ signMode: 'BUILD',
436
+ enableCustomComponent: true
437
+ });
438
+ // 1.3
439
+ _process.stdout.write = originalStdout;
440
+ // 2.
441
+ context.liteCards.forEach(card => {
442
+ // hap-toolkit的产物在项目的build文件夹下
443
+ const fromPath = _path.default.join(context.projectPath, LITE_OUTPUT_PATH, card);
444
+ // aiot-toolkit的产物在临时项目的build文件夹下
445
+ const toPath = _path.default.join(projectPath, LITE_OUTPUT_PATH, card);
446
+ //确定目标目录存在,若不存在则创建到父目录
447
+ _fsExtra.default.ensureDirSync(_path.default.dirname(toPath));
448
+ // 复制文件
449
+ _fsExtra.default.moveSync(fromPath + '.template.json', toPath + '.template.json', {
450
+ overwrite: true
451
+ });
452
+ _fsExtra.default.moveSync(fromPath + '.css.json', toPath + '.css.json', {
453
+ overwrite: true
454
+ });
455
+ });
456
+ }
457
+ } catch (error) {
458
+ throw new Error(`compile lite card error, ${error?.toString() || 'unknown error'}.`);
459
+ }
460
+ };
461
+ /**
462
+ * 检查资源文件
463
+ * 1. 检查文件体积是否过大, 如果超出,则提示到真机验证
464
+ * @param params
465
+ */
466
+ static resourceCheck = async params => {
467
+ const {
468
+ context,
469
+ compilerOption,
470
+ onLog
471
+ } = params;
472
+ if (!compilerOption) {
473
+ return;
474
+ }
475
+
476
+ // 最大值,单位KB
477
+ const MAX_SIZE = 1024;
478
+ const {
479
+ projectPath
480
+ } = context;
481
+ const {
482
+ outputPath
483
+ } = compilerOption;
484
+ const fileList = _sharedUtils.FileUtil.readAlldirSync(_path.default.join(projectPath, outputPath));
485
+ const largeFileList = fileList.filter(item => {
486
+ const status = _fsExtra.default.statSync(item);
487
+ return status.size > MAX_SIZE * 1024;
488
+ });
489
+ if (largeFileList.length) {
490
+ const logs = [];
491
+ logs.push({
492
+ level: _sharedUtils.Loglevel.WARN,
493
+ message: [`the following files is large than`, {
494
+ word: `${MAX_SIZE}KB`
495
+ }, `, please check on the`, {
496
+ word: `real device\r\n`
497
+ }, {
498
+ word: largeFileList.map((item, index) => `${index + 1}. ${item}`).join('\r\n ')
499
+ }]
500
+ });
501
+ onLog?.(logs);
502
+ }
503
+ };
504
+
505
+ /**
506
+ * 写入.gitignore文件, 忽略临时目录
507
+ */
508
+ static writeGitIgnore = async params => {
509
+ const {
510
+ context
511
+ } = params;
512
+ const {
513
+ output,
514
+ projectPath
515
+ } = context;
516
+ const gitIgnorePath = _path.default.join(projectPath, output, '.gitignore');
517
+ _fsExtra.default.writeFileSync(gitIgnorePath, '*');
518
+ };
364
519
  }
365
520
  var _default = exports.default = UxAfterCompile;
@@ -9,7 +9,7 @@ var _fileLane = require("file-lane");
9
9
  class UxAfterWorks {
10
10
  static async cleanOutput(context) {
11
11
  const outputPath = _fileLane.FileLaneUtil.getOutputPath(context);
12
- _sharedUtils.FileUtil.del(outputPath);
12
+ await _sharedUtils.FileUtil.del(outputPath);
13
13
  }
14
14
  }
15
15
  var _default = exports.default = UxAfterWorks;
@@ -1,9 +1,23 @@
1
+ import { ILog } from '@aiot-toolkit/shared-utils';
2
+ import { IFileLaneContext } from 'file-lane';
1
3
  import ICompileParam from '../interface/ICompileParam';
2
4
  import ICompiler from '../interface/ICompiler';
3
5
  import IJavascriptCompileOption from './interface/IJavascriptCompileOption';
4
6
  declare class JavascriptCompiler implements ICompiler {
7
+ private readonly context;
8
+ private readonly onLog?;
5
9
  readonly QUICKAPP_CONFIG = "quickapp.config.js";
10
+ constructor(context: IFileLaneContext, onLog?: ((log: ILog[]) => void) | undefined);
6
11
  compile(param: IJavascriptCompileOption): Promise<void>;
12
+ /**
13
+ * 压缩插件
14
+ *
15
+ * dev模式,只处理console,其它禁用
16
+ * prod模式,其它使用默认值
17
+ * @param mode
18
+ * @returns
19
+ */
20
+ private createMinimizerRspackPlugin;
7
21
  private createWebpackConfig;
8
22
  private getConfigurator;
9
23
  clean(param: ICompileParam & IJavascriptCompileOption): Promise<void>;
@@ -8,12 +8,17 @@ var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
8
  var _core = require("@rspack/core");
9
9
  var _lodash = _interopRequireDefault(require("lodash"));
10
10
  var _path = _interopRequireDefault(require("path"));
11
+ var _CompileMode = _interopRequireDefault(require("../enum/CompileMode"));
11
12
  var _AndroidWebpackConfigurator = _interopRequireDefault(require("./android/AndroidWebpackConfigurator"));
12
13
  var _VelaWebpackConfigurator = _interopRequireDefault(require("./vela/VelaWebpackConfigurator"));
13
14
  var _UxCompileUtil = _interopRequireDefault(require("./vela/utils/UxCompileUtil"));
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
16
  class JavascriptCompiler {
16
17
  QUICKAPP_CONFIG = 'quickapp.config.js';
18
+ constructor(context, onLog) {
19
+ this.context = context;
20
+ this.onLog = onLog;
21
+ }
17
22
  async compile(param) {
18
23
  return new Promise(async (resolve, reject) => {
19
24
  try {
@@ -49,6 +54,65 @@ class JavascriptCompiler {
49
54
  }
50
55
  });
51
56
  }
57
+
58
+ /**
59
+ * 压缩插件
60
+ *
61
+ * dev模式,只处理console,其它禁用
62
+ * prod模式,其它使用默认值
63
+ * @param mode
64
+ * @returns
65
+ */
66
+ createMinimizerRspackPlugin(compileOption) {
67
+ const {
68
+ mode,
69
+ dropConsole
70
+ } = compileOption;
71
+ const translateDropConsole = () => {
72
+ let dropConsoleValue;
73
+ if (dropConsole === undefined) {
74
+ dropConsoleValue = false;
75
+ } else if (dropConsole === 'true') {
76
+ dropConsoleValue = true;
77
+ } else if (dropConsole === 'false') {
78
+ dropConsoleValue = false;
79
+ } else {
80
+ dropConsoleValue = dropConsole;
81
+ }
82
+ return dropConsoleValue;
83
+ };
84
+ const createCompressValue = dropConsoleValue => {
85
+ const result = {};
86
+ if (typeof dropConsoleValue === 'boolean') {
87
+ result.drop_console = dropConsoleValue;
88
+ } else if (typeof dropConsoleValue === 'string') {
89
+ result.pure_funcs = dropConsoleValue.split(',').map(item => item.trim()).filter(Boolean).map(item => `console.${item}`);
90
+ }
91
+ return result;
92
+ };
93
+ if (mode === _CompileMode.default.DEVELOPMENT) {
94
+ return new _core.rspack.SwcJsMinimizerRspackPlugin({
95
+ minimizerOptions: {
96
+ module: true,
97
+ minify: false,
98
+ mangle: false,
99
+ compress: {
100
+ defaults: false,
101
+ ...createCompressValue(translateDropConsole())
102
+ }
103
+ }
104
+ });
105
+ } else {
106
+ return new _core.rspack.SwcJsMinimizerRspackPlugin({
107
+ minimizerOptions: {
108
+ module: true,
109
+ compress: {
110
+ ...createCompressValue(translateDropConsole())
111
+ }
112
+ }
113
+ });
114
+ }
115
+ }
52
116
  createWebpackConfig(param) {
53
117
  const configurator = this.getConfigurator(param);
54
118
  if (!configurator) {
@@ -82,17 +146,39 @@ class JavascriptCompiler {
82
146
  rules: [{
83
147
  test: /\.ux$/,
84
148
  // 匹配以 .ux 结尾的文件
149
+ exclude: /node_modules/,
85
150
  use: [{
86
151
  loader: _path.default.join(__dirname, '../javascript/vela/utils/webpackLoader/extractMapData.js')
87
152
  }]
153
+ },
154
+ // node_modules下的ux文件
155
+ {
156
+ test: /\.ux$/,
157
+ include: /node_modules/,
158
+ use: [{
159
+ loader: _path.default.join(__dirname, '../javascript/vela/utils/webpackLoader/WebpackUxLoader'),
160
+ options: {
161
+ compileParam: param,
162
+ context: this.context,
163
+ onLog: this.onLog
164
+ }
165
+ }]
166
+ }, {
167
+ test: /\.js$/,
168
+ include: /node_modules/,
169
+ use: [{
170
+ loader: _path.default.join(__dirname, '../javascript/vela/utils/webpackLoader/WebpackJsLoader'),
171
+ options: {
172
+ compileParam: param,
173
+ context: this.context,
174
+ onLog: this.onLog
175
+ }
176
+ }]
88
177
  }]
89
178
  },
90
179
  optimization: {
91
- minimizer: [new _core.rspack.SwcJsMinimizerRspackPlugin({
92
- minimizerOptions: {
93
- module: true
94
- }
95
- })]
180
+ minimize: true,
181
+ minimizer: [this.createMinimizerRspackPlugin(param)]
96
182
  },
97
183
  resolve: {
98
184
  extensions: ['.js', '.ts', '.ux']
@@ -1,6 +1,6 @@
1
1
  import ICompileParam from '../../interface/ICompileParam';
2
2
  import BuildNameFormatType from '../vela/enum/BuildNameFormatType';
3
- export default interface IJavascriptCompileOption extends ICompileParam {
3
+ interface IJavascriptCompileOption extends ICompileParam {
4
4
  devtool?: string | false;
5
5
  /**
6
6
  * 源码路径(相对项目根目录)
@@ -48,6 +48,10 @@ export default interface IJavascriptCompileOption extends ICompileParam {
48
48
  * 启用应用自动化测试
49
49
  */
50
50
  enableE2e?: boolean;
51
+ /**
52
+ * 启用 png8 压缩
53
+ */
54
+ enableImagePng8?: boolean;
51
55
  /**
52
56
  * 启用代码体积分析,会生成 report.html 文件,可查看打包后各模块占用体积
53
57
  */
@@ -56,6 +60,21 @@ export default interface IJavascriptCompileOption extends ICompileParam {
56
60
  * 是否自动补全 manifest.json 中的 features 配置
57
61
  */
58
62
  completeFeature?: boolean;
63
+ /**
64
+ * 是否删除 console
65
+ *
66
+ * true:删除全部 console
67
+ * string: 指定要去除的console,如'log'、'warn'、'error'
68
+ *
69
+ * @example true
70
+ *
71
+ * @example log,warn
72
+ */
73
+ dropConsole?: boolean | string;
74
+ /**
75
+ * 启动页
76
+ */
77
+ startPage?: string;
59
78
  /**
60
79
  * 获取远程证书
61
80
  */
@@ -70,3 +89,4 @@ export default interface IJavascriptCompileOption extends ICompileParam {
70
89
  certificate: Buffer;
71
90
  }>;
72
91
  }
92
+ export default IJavascriptCompileOption;
@@ -1 +1,5 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -1,4 +1,13 @@
1
1
  import { Dictionary } from '@aiot-toolkit/shared-utils';
2
+ export declare const LITE_CARD_TYPE = "lite";
3
+ interface IWidget {
4
+ name: string;
5
+ component: string;
6
+ minCardPlatformVersion: Number;
7
+ providerUri: string;
8
+ sizes: string[];
9
+ type?: string;
10
+ }
2
11
  /**
3
12
  * vela manifest文件对应的数据结构
4
13
  */
@@ -16,6 +25,7 @@ export default interface IManifest {
16
25
  designWidth?: string | number;
17
26
  };
18
27
  router: {
28
+ widgets?: Record<string, IWidget>;
19
29
  entry: string;
20
30
  pages: Dictionary<{
21
31
  component?: string;
@@ -28,3 +38,4 @@ export default interface IManifest {
28
38
  export interface IFeatures {
29
39
  name: string;
30
40
  }
41
+ export {};
@@ -1 +1,11 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LITE_CARD_TYPE = void 0;
7
+ const LITE_CARD_TYPE = exports.LITE_CARD_TYPE = 'lite';
8
+
9
+ /**
10
+ * vela manifest文件对应的数据结构
11
+ */
@@ -33,8 +33,7 @@ class WrapPlugin {
33
33
  const source = compilation.assets[entry];
34
34
  const isApp = entry === 'app.js';
35
35
  const createFuncnName = isApp ? 'createAppHandler' : 'createPageHandler';
36
- compilation.assets[entry] = new _webpackSources.ConcatSource(`
37
- export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
36
+ compilation.assets[entry] = new _webpackSources.ConcatSource(`export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
38
37
  var org_app_require = $app_require$;
39
38
 
40
39
  (function(global, globalThis, window, $app_exports$, $app_evaluate$){
@@ -45,8 +44,6 @@ class WrapPlugin {
45
44
  var $app_require$ = global.$app_require$ || org_app_require
46
45
 
47
46
  ${enableE2e ? `globalThis = undefined; \n global = typeof window === "undefined" ? global.__proto__ : window;` : ''}
48
- // 转换动态 style 的函数
49
- ${isApp ? this.translateStyleFunc() : ''}
50
47
  var ${createFuncnName} = function() {
51
48
  return `, source, `
52
49
  }
@@ -8,6 +8,7 @@ var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
8
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
9
  var _path = _interopRequireDefault(require("path"));
10
10
  var _EntryType = _interopRequireDefault(require("../enum/EntryType"));
11
+ var _IManifest = require("../interface/IManifest");
11
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
13
  class UxCompileUtil {
13
14
  // 摘要文件夹
@@ -80,6 +81,10 @@ class UxCompileUtil {
80
81
  throw new Error(`Compilation failed: please confirm that '${routePath}' configured by router.pages in manifest.json is the directory name`);
81
82
  }
82
83
  const conf = confs[routePath];
84
+ //轻卡无需打包
85
+ if (conf.type === _IManifest.LITE_CARD_TYPE) {
86
+ return;
87
+ }
83
88
  const entryKey = _path.default.join(routePath, conf.component);
84
89
  const filePath = this.resolveFile(_path.default.join(codeDir, entryKey));
85
90
  if (!filePath) {
@@ -0,0 +1,11 @@
1
+ import { IFileLaneContext } from 'file-lane';
2
+ import IJavascriptCompileOption from '../../../interface/IJavascriptCompileOption';
3
+ import { ILog } from '@aiot-toolkit/shared-utils';
4
+ /**
5
+ * IWebpackLoaderOption
6
+ */
7
+ export default interface IWebpackLoaderOption {
8
+ compileParam: IJavascriptCompileOption;
9
+ context: IFileLaneContext;
10
+ onLog: (log: ILog[]) => void;
11
+ }
@@ -0,0 +1,2 @@
1
+ import { LoaderContext } from '@rspack/core';
2
+ export default function (this: LoaderContext<any>, source: string): Promise<void>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ var _parser = require("@aiot-toolkit/parser");
8
+ var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
+ async function _default(source) {
10
+ const callback = this.async();
11
+ const options = this.getOptions();
12
+ const {
13
+ context,
14
+ onLog,
15
+ compileParam
16
+ } = options;
17
+ const result = await new _parser.ScriptToTypescript({
18
+ filePath: this.resourcePath,
19
+ content: source,
20
+ projectPath: this.rootContext,
21
+ onLog: log => onLog?.([log]),
22
+ projectType: _sharedUtils.ProjectType.VELA_UX
23
+ }, compileParam, context).translate({
24
+ content: source
25
+ }, []);
26
+ callback(null, result.targetTree.getFullText());
27
+ }
@@ -0,0 +1,2 @@
1
+ import { LoaderContext } from '@rspack/core';
2
+ export default function (this: LoaderContext<any>, source: string): Promise<void>;