@aiot-toolkit/aiotpack 2.0.2-beta.4 → 2.0.2-beta.5

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.
@@ -45,4 +45,8 @@ export default interface IJavascriptCompileOption extends ICompileParam {
45
45
  * 启用应用自动化测试
46
46
  */
47
47
  enableE2e?: boolean;
48
+ /**
49
+ * 启用代码体积分析,会生成 report.html 文件,可查看打包后各模块占用体积
50
+ */
51
+ enableStats?: boolean;
48
52
  }
@@ -10,10 +10,20 @@ const WrapPlugin_1 = __importDefault(require("./plugin/WrapPlugin"));
10
10
  const UxCompileUtil_1 = __importDefault(require("./utils/UxCompileUtil"));
11
11
  class VelaWebpackConfigurator {
12
12
  createPlugins() {
13
- return [
13
+ const result = [
14
14
  // 给 入口js 添加包裹
15
15
  new WrapPlugin_1.default()
16
16
  ];
17
+ // 如果开启 stats 参数,则添加 webpack-bundle-analyzer 插件
18
+ if (this.param.enableStats) {
19
+ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
20
+ result.push(new BundleAnalyzerPlugin({
21
+ analyzerMode: 'static',
22
+ openAnalyzer: false,
23
+ excludeAssets: /^@(system|service)\./
24
+ }));
25
+ }
26
+ return result;
17
27
  }
18
28
  /**
19
29
  * 通过读取 manifest.json 生成 entry
@@ -40,7 +50,6 @@ class VelaWebpackConfigurator {
40
50
  {
41
51
  loader: require.resolve('babel-loader'),
42
52
  options: {
43
- // configFile: getBabelConfigJsPath(cwd),
44
53
  cwd: this.param.projectPath,
45
54
  cacheDirectory: true
46
55
  }
@@ -40,10 +40,11 @@ const UxParser_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/parser/U
40
40
  const UxToTypescript_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/UxToTypescript"));
41
41
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
42
42
  const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
43
- const StringUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/StringUtil"));
44
43
  const parse5 = __importStar(require("parse5"));
45
44
  const path_1 = __importDefault(require("path"));
45
+ const fs_extra_1 = __importDefault(require("fs-extra"));
46
46
  const ts_morph_1 = require("ts-morph");
47
+ const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
47
48
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
48
49
  const { extractFunctions } = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/protobufControl');
49
50
  /**
@@ -85,9 +86,25 @@ class UxLoaderUtils {
85
86
  logs.push(log);
86
87
  }
87
88
  };
89
+ // 收集图片资源
90
+ const ImageResources = [];
91
+ const collectImageResource = (originFilePath) => {
92
+ const assetDir = 'dynamicAssets';
93
+ const sourcePath = path_1.default.resolve(options.projectPath, compilerOption.sourceRoot);
94
+ const assetPath = path_1.default.resolve(sourcePath, assetDir);
95
+ const { name, ext } = path_1.default.parse(originFilePath);
96
+ const hashName = CommonUtil_1.default.calcImageDigest(originFilePath);
97
+ const newFilePath = path_1.default.join(assetPath, `${name}-${hashName}${ext}`);
98
+ const relativePath = path_1.default.posix.sep + path_1.default.relative(sourcePath, newFilePath);
99
+ ImageResources.push({
100
+ path: newFilePath,
101
+ content: fs_extra_1.default.readFileSync(originFilePath)
102
+ });
103
+ return relativePath;
104
+ };
88
105
  // 开始转换
89
106
  const globalVar = ('globalVar' in context && context.globalVar) || {};
90
- const parserResult = yield new UxParser_1.default(options, globalVar).parser(content.toString(), fullName);
107
+ const parserResult = yield new UxParser_1.default(options, compilerOption, globalVar, collectImageResource).parser(content.toString(), fullName);
91
108
  // 区分app.ux和一般ux
92
109
  // app.ux解析结果中加上manifest.json的内容
93
110
  const manifestJson = `require('./manifest.json')`;
@@ -96,7 +113,7 @@ class UxLoaderUtils {
96
113
  return isAppUx
97
114
  ? [
98
115
  `${appImport.join('\n')}`,
99
- `var $app_style$ = ${UxLoaderUtils.wrapStyle(StringUtil_1.default.arrayTostring(appStyleTree, true), file, compilerOption)}`,
116
+ `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
100
117
  `var $app_script$ = ${UxLoaderUtils.handleScriptContent(false, appScriptTree)}\n`,
101
118
  `$app_script$({}, $app_exports$, $app_require$);\n\n`,
102
119
  `$app_exports$.default.style = $app_style$;`,
@@ -104,7 +121,7 @@ class UxLoaderUtils {
104
121
  ]
105
122
  : [
106
123
  `${appImport.join('\n')}`,
107
- `var $app_style$ = ${UxLoaderUtils.wrapStyle(StringUtil_1.default.arrayTostring(appStyleTree, true), file, compilerOption)}\n`,
124
+ `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}\n`,
108
125
  `var $app_script$ = ${UxLoaderUtils.handleScriptContent(isPageUx, appScriptTree)}`,
109
126
  `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}\n`,
110
127
  `${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`,
@@ -131,7 +148,8 @@ class UxLoaderUtils {
131
148
  {
132
149
  path: FileUtil_1.default.updatePath(filePath, `${name}.js.map`),
133
150
  content: sourceMap.toString()
134
- }
151
+ },
152
+ ...ImageResources
135
153
  ],
136
154
  logs
137
155
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.2-beta.4",
3
+ "version": "2.0.2-beta.5",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,13 +19,13 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.2-beta.4",
23
- "@aiot-toolkit/parser": "2.0.2-beta.4",
22
+ "@aiot-toolkit/generator": "2.0.2-beta.5",
23
+ "@aiot-toolkit/parser": "2.0.2-beta.5",
24
24
  "@hap-toolkit/aaptjs": "^2.0.0",
25
25
  "babel-loader": "^9.1.3",
26
26
  "del": "^4.1.0",
27
27
  "fast-glob": "^3.3.2",
28
- "file-lane": "2.0.2-beta.4",
28
+ "file-lane": "2.0.2-beta.5",
29
29
  "file-loader": "^6.2.0",
30
30
  "fs-extra": "^11.2.0",
31
31
  "jsrsasign": "^7.2.2",
@@ -33,11 +33,13 @@
33
33
  "source-map": "^0.7.4",
34
34
  "url-loader": "^4.1.1",
35
35
  "webpack": "^5.89.0",
36
+ "webpack-bundle-analyzer": "^4.10.1",
36
37
  "webpack-sources": "^3.2.3"
37
38
  },
38
39
  "devDependencies": {
40
+ "@types/fs-extra": "^11.0.4",
39
41
  "@types/jsrsasign": "^10.5.12",
40
42
  "@types/webpack-sources": "^3.2.3"
41
43
  },
42
- "gitHead": "656add8e64d8101b9f3886957c5b9ae23e2e854f"
44
+ "gitHead": "8c18753992c453c6569a3125378e75fbf4760a1f"
43
45
  }