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

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 +161 -16
  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 +17 -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));
@@ -251,6 +255,37 @@ class UxAfterCompile {
251
255
  await genMetaFiles(compilerOption);
252
256
  }
253
257
  };
258
+
259
+ /**
260
+ * 压缩资源文件
261
+ * 1. png8
262
+ * 2. bin
263
+ * @param params
264
+ */
265
+ static compressResource = async params => {
266
+ const {
267
+ compilerOption
268
+ } = params;
269
+ if (compilerOption) {
270
+ const {
271
+ enableImagePng8,
272
+ projectPath,
273
+ outputPath
274
+ } = compilerOption;
275
+ if (enableImagePng8) {
276
+ const format = 'png';
277
+ const files = _sharedUtils.FileUtil.readAlldirSync(_path.default.join(projectPath, outputPath));
278
+ const compressFiles = files.filter(filePath => _ImageIcu.default.canTranslate(filePath, format));
279
+ if (compressFiles.length) {
280
+ const icu = new _ImageIcu.default();
281
+ compressFiles.forEach(item => {
282
+ icu.translate(item, _path.default.dirname(item), format);
283
+ });
284
+ }
285
+ }
286
+ }
287
+ };
288
+
254
289
  /**
255
290
  * 如果是更新触发,则对比临时项目build文件夹 和 项目build文件夹,生成diff.json
256
291
  * @param context
@@ -261,7 +296,7 @@ class UxAfterCompile {
261
296
  const {
262
297
  compilerOption,
263
298
  compalition,
264
- config
299
+ context
265
300
  } = params;
266
301
  if (!compilerOption || !compalition) {
267
302
  return;
@@ -269,19 +304,16 @@ class UxAfterCompile {
269
304
  if (compalition.trigger === _FileLaneTriggerType.default.START) {
270
305
  return;
271
306
  }
272
- const {
273
- outputPath,
274
- projectPath
275
- } = compilerOption;
276
307
  // 读取临时项目build文件夹中所有文件路径
277
- const tempBuildPath = _path.default.join(projectPath, outputPath);
308
+ const tempBuildDir = _path.default.join(compilerOption.projectPath, compilerOption.outputPath);
278
309
  // 待优化,map文件跟随源文件变化,与时间戳有关文件无需对比
279
- const tempFileList = _sharedUtils.FileUtil.readAlldirSync(tempBuildPath).map(filePath => _path.default.relative(tempBuildPath, filePath));
280
- const diffList = _UxFileUtils.default.getDiffJSON(compalition, tempFileList, tempBuildPath);
310
+ const tempFileList = _sharedUtils.FileUtil.readAlldirSync(tempBuildDir);
311
+ const buildDir = _path.default.join(context.projectPath, compilerOption.outputPath);
312
+ const diffList = _UxFileUtils.default.getDiffJSON(compalition.buildFileList, tempFileList, buildDir, tempBuildDir);
281
313
 
282
314
  // 所有差异文件,压缩到 .diff.rpk 中
283
315
  if (diffList?.length) {
284
- const buildFold = _path.default.join(compilerOption.projectPath, compilerOption.outputPath);
316
+ const buildFold = tempBuildDir;
285
317
  const distFold = _path.default.join(compilerOption.projectPath, compilerOption.releasePath);
286
318
  const diffFileName = `.diff.rpk`;
287
319
  const diffPath = _path.default.join(distFold, diffFileName);
@@ -290,7 +322,7 @@ class UxAfterCompile {
290
322
  zipFilePath: item
291
323
  })));
292
324
  compalition.info.diffList = diffList;
293
- compalition.info.diffFile = _path.default.join(config.projectPath, compilerOption.releasePath, diffFileName);
325
+ compalition.info.diffFile = _path.default.join(context.projectPath, compilerOption.releasePath, diffFileName);
294
326
  }
295
327
  };
296
328
 
@@ -361,5 +393,118 @@ class UxAfterCompile {
361
393
  throw new Error(`${error?.toString() || 'unknown error'}. Please check whether the file system of the current disk supports the creation of soft links.`);
362
394
  }
363
395
  };
396
+ /**
397
+ * 编译轻卡ux
398
+ * 1. 使用hap-toolkit编译项目,编译结果存储在build文件夹
399
+ * 1.1 重写stdout以捕获hap-toolkit中的正常日志,错误日志正常输出
400
+ * 1.2 使用hap-toolkit编译项目
401
+ * 1.3 还原stdout
402
+ * 2. 取widgets中配置的轻卡内容,将build文件夹中对应的产物复制到临时文件夹
403
+ * @param params
404
+ */
405
+ static compileLiteCard = async params => {
406
+ const {
407
+ compilerOption,
408
+ context
409
+ } = params;
410
+ try {
411
+ if (context?.liteCards?.length > 0 && compilerOption) {
412
+ const {
413
+ projectPath,
414
+ outputPath
415
+ } = compilerOption;
416
+ const LITE_OUTPUT_PATH = outputPath;
417
+ // 1.1
418
+ const originalStdout = _process.stdout.write;
419
+ _process.stdout.write = function () {
420
+ return true;
421
+ };
422
+ // 1.2
423
+ await HapToolkit.compile('native', 'dev', false, {
424
+ cwd: context.projectPath,
425
+ signMode: 'BUILD',
426
+ enableCustomComponent: true
427
+ });
428
+ // 1.3
429
+ _process.stdout.write = originalStdout;
430
+ // 2.
431
+ context.liteCards.forEach(card => {
432
+ // hap-toolkit的产物在项目的build文件夹下
433
+ const fromPath = _path.default.join(context.projectPath, LITE_OUTPUT_PATH, card);
434
+ // aiot-toolkit的产物在临时项目的build文件夹下
435
+ const toPath = _path.default.join(projectPath, LITE_OUTPUT_PATH, card);
436
+ //确定目标目录存在,若不存在则创建到父目录
437
+ _fsExtra.default.ensureDirSync(_path.default.dirname(toPath));
438
+ // 复制文件
439
+ _fsExtra.default.moveSync(fromPath + '.template.json', toPath + '.template.json', {
440
+ overwrite: true
441
+ });
442
+ _fsExtra.default.moveSync(fromPath + '.css.json', toPath + '.css.json', {
443
+ overwrite: true
444
+ });
445
+ });
446
+ }
447
+ } catch (error) {
448
+ throw new Error(`compile lite card error, ${error?.toString() || 'unknown error'}.`);
449
+ }
450
+ };
451
+ /**
452
+ * 检查资源文件
453
+ * 1. 检查文件体积是否过大, 如果超出,则提示到真机验证
454
+ * @param params
455
+ */
456
+ static resourceCheck = async params => {
457
+ const {
458
+ context,
459
+ compilerOption,
460
+ onLog
461
+ } = params;
462
+ if (!compilerOption) {
463
+ return;
464
+ }
465
+
466
+ // 最大值,单位KB
467
+ const MAX_SIZE = 1024;
468
+ const {
469
+ projectPath
470
+ } = context;
471
+ const {
472
+ outputPath
473
+ } = compilerOption;
474
+ const fileList = _sharedUtils.FileUtil.readAlldirSync(_path.default.join(projectPath, outputPath));
475
+ const largeFileList = fileList.filter(item => {
476
+ const status = _fsExtra.default.statSync(item);
477
+ return status.size > MAX_SIZE * 1024;
478
+ });
479
+ if (largeFileList.length) {
480
+ const logs = [];
481
+ logs.push({
482
+ level: _sharedUtils.Loglevel.WARN,
483
+ message: [`the following files is large than`, {
484
+ word: `${MAX_SIZE}KB`
485
+ }, `, please check on the`, {
486
+ word: `real device\r\n`
487
+ }, {
488
+ word: largeFileList.map((item, index) => `${index + 1}. ${item}`).join('\r\n ')
489
+ }]
490
+ });
491
+ onLog?.(logs);
492
+ }
493
+ };
494
+
495
+ /**
496
+ * 写入.gitignore文件, 忽略临时目录
497
+ */
498
+ static writeGitIgnore = async params => {
499
+ const {
500
+ context
501
+ } = params;
502
+ const {
503
+ output,
504
+ projectPath
505
+ } = context;
506
+ const gitIgnorePath = _path.default.join(projectPath, output, '.gitignore');
507
+ _fsExtra.default.writeFileSync(gitIgnorePath, '*');
508
+ };
364
509
  }
365
510
  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,17 @@ 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;
59
74
  /**
60
75
  * 获取远程证书
61
76
  */
@@ -70,3 +85,4 @@ export default interface IJavascriptCompileOption extends ICompileParam {
70
85
  certificate: Buffer;
71
86
  }>;
72
87
  }
88
+ 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>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ var _UxLoaderUtils = _interopRequireDefault(require("../../../../../utils/ux/UxLoaderUtils"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ async function _default(source) {
10
+ const options = this.getOptions();
11
+ const {
12
+ onLog,
13
+ compileParam,
14
+ context
15
+ } = options;
16
+ const callback = this.async();
17
+ const {
18
+ files: compiledFiles,
19
+ logs
20
+ } = await _UxLoaderUtils.default.compileUxToJavascript({
21
+ path: this.resourcePath,
22
+ content: source
23
+ }, context, false, compileParam);
24
+ onLog?.(logs);
25
+ callback(null, compiledFiles[0].content, compiledFiles[1].content);
26
+ }