@aiot-toolkit/aiotpack 2.0.5-beta.15 → 2.0.5-beta.16

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.
@@ -320,8 +320,8 @@ class UxAfterCompile {
320
320
  const diffFileName = `.diff.rpk`;
321
321
  const diffPath = _path.default.join(distFold, diffFileName);
322
322
  await _ZipFileUtil.default.createZipFile(diffPath, diffList.map(item => ({
323
- filePath: _path.default.join(buildFold, item),
324
- zipFilePath: item
323
+ filePath: _path.default.join(buildFold, item.path),
324
+ zipFilePath: item.path
325
325
  })));
326
326
  compalition.info.diffList = diffList;
327
327
  compalition.info.diffFile = _path.default.join(context.projectPath, compilerOption.releasePath, diffFileName);
@@ -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;
@@ -4,6 +4,15 @@ import IJavascriptCompileOption from './interface/IJavascriptCompileOption';
4
4
  declare class JavascriptCompiler implements ICompiler {
5
5
  readonly QUICKAPP_CONFIG = "quickapp.config.js";
6
6
  compile(param: IJavascriptCompileOption): Promise<void>;
7
+ /**
8
+ * 压缩插件
9
+ *
10
+ * dev模式,只处理console,其它禁用
11
+ * prod模式,其它使用默认值
12
+ * @param mode
13
+ * @returns
14
+ */
15
+ private createMinimizerRspackPlugin;
7
16
  private createWebpackConfig;
8
17
  private getConfigurator;
9
18
  clean(param: ICompileParam & IJavascriptCompileOption): Promise<void>;
@@ -11,6 +11,7 @@ var _path = _interopRequireDefault(require("path"));
11
11
  var _AndroidWebpackConfigurator = _interopRequireDefault(require("./android/AndroidWebpackConfigurator"));
12
12
  var _VelaWebpackConfigurator = _interopRequireDefault(require("./vela/VelaWebpackConfigurator"));
13
13
  var _UxCompileUtil = _interopRequireDefault(require("./vela/utils/UxCompileUtil"));
14
+ var _CompileMode = _interopRequireDefault(require("../enum/CompileMode"));
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
16
  class JavascriptCompiler {
16
17
  QUICKAPP_CONFIG = 'quickapp.config.js';
@@ -49,6 +50,65 @@ class JavascriptCompiler {
49
50
  }
50
51
  });
51
52
  }
53
+
54
+ /**
55
+ * 压缩插件
56
+ *
57
+ * dev模式,只处理console,其它禁用
58
+ * prod模式,其它使用默认值
59
+ * @param mode
60
+ * @returns
61
+ */
62
+ createMinimizerRspackPlugin(compileOption) {
63
+ const {
64
+ mode,
65
+ dropConsole
66
+ } = compileOption;
67
+ const translateDropConsole = () => {
68
+ let dropConsoleValue;
69
+ if (dropConsole === undefined) {
70
+ dropConsoleValue = false;
71
+ } else if (dropConsole === 'true') {
72
+ dropConsoleValue = true;
73
+ } else if (dropConsole === 'false') {
74
+ dropConsoleValue = false;
75
+ } else {
76
+ dropConsoleValue = dropConsole;
77
+ }
78
+ return dropConsoleValue;
79
+ };
80
+ const createCompressValue = dropConsoleValue => {
81
+ const result = {};
82
+ if (typeof dropConsoleValue === 'boolean') {
83
+ result.drop_console = dropConsoleValue;
84
+ } else if (typeof dropConsoleValue === 'string') {
85
+ result.pure_funcs = dropConsoleValue.split(',').map(item => item.trim()).filter(Boolean).map(item => `console.${item}`);
86
+ }
87
+ return result;
88
+ };
89
+ if (mode === _CompileMode.default.DEVELOPMENT) {
90
+ return new _core.rspack.SwcJsMinimizerRspackPlugin({
91
+ minimizerOptions: {
92
+ module: true,
93
+ minify: false,
94
+ mangle: false,
95
+ compress: {
96
+ defaults: false,
97
+ ...createCompressValue(translateDropConsole())
98
+ }
99
+ }
100
+ });
101
+ } else {
102
+ return new _core.rspack.SwcJsMinimizerRspackPlugin({
103
+ minimizerOptions: {
104
+ module: true,
105
+ compress: {
106
+ ...createCompressValue(translateDropConsole())
107
+ }
108
+ }
109
+ });
110
+ }
111
+ }
52
112
  createWebpackConfig(param) {
53
113
  const configurator = this.getConfigurator(param);
54
114
  if (!configurator) {
@@ -88,11 +148,8 @@ class JavascriptCompiler {
88
148
  }]
89
149
  },
90
150
  optimization: {
91
- minimizer: [new _core.rspack.SwcJsMinimizerRspackPlugin({
92
- minimizerOptions: {
93
- module: true
94
- }
95
- })]
151
+ minimize: true,
152
+ minimizer: [this.createMinimizerRspackPlugin(param)]
96
153
  },
97
154
  resolve: {
98
155
  extensions: ['.js', '.ts', '.ux']
@@ -60,6 +60,17 @@ export default interface IJavascriptCompileOption extends ICompileParam {
60
60
  * 是否自动补全 manifest.json 中的 features 配置
61
61
  */
62
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;
63
74
  /**
64
75
  * 获取远程证书
65
76
  */
@@ -48,6 +48,9 @@ export declare class UxFileUtils {
48
48
  * @param newFileList 新文件列表
49
49
  * @returns
50
50
  */
51
- static getDiffJSON(compilation: FileLaneCompilation, newFileList: string[], buildPath: string): string[];
51
+ static getDiffJSON(compilation: FileLaneCompilation, newFileList: string[], buildPath: string): {
52
+ path: string;
53
+ content: Buffer;
54
+ }[];
52
55
  }
53
56
  export default UxFileUtils;
@@ -135,16 +135,22 @@ class UxFileUtils {
135
135
  if (index !== -1) {
136
136
  // 1.2
137
137
  const oldContent = oldFileList[i].content?.toString('utf-8');
138
- const newContent = _fsExtra.default.readFileSync(_path.default.join(buildPath, newFileList[index]), 'utf-8');
139
- if (oldContent !== newContent) {
140
- diffList.push(newFileList[index]);
138
+ const newContent = _fsExtra.default.readFileSync(_path.default.join(buildPath, newFileList[index]));
139
+ if (oldContent !== newContent.toString()) {
140
+ diffList.push({
141
+ path: newFileList[index],
142
+ content: newContent
143
+ });
141
144
  }
142
145
  // 从newFileList中移除该项
143
146
  newFileList.splice(index, 1);
144
147
  }
145
148
  }
146
149
  // 2.
147
- newFileList.length > 0 && newFileList.forEach(file => diffList.push(file));
150
+ newFileList.length > 0 && newFileList.forEach(file => diffList.push({
151
+ path: file,
152
+ content: _fsExtra.default.readFileSync(_path.default.join(buildPath, file))
153
+ }));
148
154
  return diffList;
149
155
  }
150
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.5-beta.15",
3
+ "version": "2.0.5-beta.16",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,14 +19,14 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.5-beta.15",
23
- "@aiot-toolkit/parser": "2.0.5-beta.15",
24
- "@aiot-toolkit/shared-utils": "2.0.5-beta.15",
22
+ "@aiot-toolkit/generator": "2.0.5-beta.16",
23
+ "@aiot-toolkit/parser": "2.0.5-beta.16",
24
+ "@aiot-toolkit/shared-utils": "2.0.5-beta.16",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
26
  "@rspack/core": "^1.3.9",
27
27
  "aiot-parse5": "^1.0.2",
28
28
  "babel-loader": "^9.1.3",
29
- "file-lane": "2.0.5-beta.15",
29
+ "file-lane": "2.0.5-beta.16",
30
30
  "file-loader": "^6.2.0",
31
31
  "fs-extra": "^11.2.0",
32
32
  "hap-toolkit": "^2.0.0",
@@ -43,5 +43,5 @@
43
43
  "@types/jsrsasign": "^10.5.12",
44
44
  "@types/webpack-sources": "^3.2.3"
45
45
  },
46
- "gitHead": "6e39bae7f788a36a777e08545d862b87fab26a9b"
46
+ "gitHead": "66255b9d69f9b15db10283d662f94f3d1f2486c3"
47
47
  }