@aiot-toolkit/aiotpack 2.0.2-dev.2 → 2.0.2-dev.4

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.
@@ -61,20 +61,31 @@ class JavascriptCompiler {
61
61
  if (configurator.create) {
62
62
  return configurator.create();
63
63
  }
64
- const { projectPath, mode, devtool, outputPath, sourceRoot } = param;
64
+ const { projectPath, mode, devtool, outputPath } = param;
65
65
  const buildPath = path_1.default.resolve(projectPath, outputPath);
66
66
  const quickAppConfig = CommonUtil_1.default.requireModule(path_1.default.join(param.projectPath, this.QUICKAPP_CONFIG));
67
67
  const result = {
68
68
  context: projectPath,
69
69
  mode,
70
- devtool,
70
+ devtool: 'source-map',
71
71
  output: {
72
72
  globalObject: 'window',
73
73
  filename: '[name].js',
74
74
  publicPath: './',
75
75
  path: buildPath
76
76
  },
77
- module: {},
77
+ module: {
78
+ rules: [
79
+ {
80
+ test: /\.js$/,
81
+ use: [
82
+ {
83
+ loader: path_1.default.join(__dirname, '../javascript/vela/utils/webpackLoader/splitMap.js')
84
+ }
85
+ ]
86
+ }
87
+ ]
88
+ },
78
89
  stats: {
79
90
  builtAt: false,
80
91
  entrypoints: false,
@@ -91,7 +102,12 @@ class JavascriptCompiler {
91
102
  result.entry = configurator.createEntry();
92
103
  }
93
104
  if (configurator.createRules && result.module) {
94
- result.module.rules = configurator.createRules();
105
+ const readyRules = result.module.rules;
106
+ const configuratorRules = configurator.createRules();
107
+ result.module.rules =
108
+ Array.isArray(readyRules) && readyRules.length > 0
109
+ ? [...configuratorRules, ...readyRules]
110
+ : configuratorRules;
95
111
  }
96
112
  if (configurator.createPlugins) {
97
113
  result.plugins = configurator.createPlugins();
@@ -1,4 +1,4 @@
1
- import { Configuration, EntryObject, RuleSetRule, WebpackPluginInstance } from 'webpack';
1
+ import { EntryObject, RuleSetRule, WebpackPluginInstance } from 'webpack';
2
2
  import ICompileParam from '../../interface/ICompileParam';
3
3
  import IJavascriptCompileOption from '../interface/IJavascriptCompileOption';
4
4
  import IWebpackConfigurator from '../interface/IWebpackConfigurator';
@@ -11,6 +11,5 @@ declare class VelaWebpackConfigurator implements IWebpackConfigurator {
11
11
  */
12
12
  createEntry(): string | EntryObject | string[];
13
13
  createRules(): RuleSetRule[];
14
- hook(config: Configuration): void;
15
14
  }
16
15
  export default VelaWebpackConfigurator;
@@ -65,8 +65,5 @@ class VelaWebpackConfigurator {
65
65
  }
66
66
  ];
67
67
  }
68
- hook(config) {
69
- // todo 合并用户配置
70
- }
71
68
  }
72
69
  exports.default = VelaWebpackConfigurator;
@@ -6,6 +6,7 @@ export default interface IManifest {
6
6
  package: string;
7
7
  name?: string;
8
8
  versionName?: string;
9
+ versionCode?: number;
9
10
  minPlatformVersion?: number;
10
11
  deviceId?: string;
11
12
  deviceTypeList?: string[];
@@ -22,6 +23,7 @@ export default interface IManifest {
22
23
  };
23
24
  minAPILevel?: number;
24
25
  packageInfo?: Dictionary<string | number>;
26
+ icon: string;
25
27
  }
26
28
  export interface IFeatures {
27
29
  name: string;
@@ -2,6 +2,5 @@ import { Compiler } from 'webpack';
2
2
  declare class WrapPlugin {
3
3
  apply(compiler: Compiler): void;
4
4
  private wrap;
5
- private wrapFunction;
6
5
  }
7
6
  export default WrapPlugin;
@@ -20,30 +20,27 @@ class WrapPlugin {
20
20
  // 从chunk找到所有入口文件,添加包裹函数
21
21
  entrys.forEach((entry) => {
22
22
  if (compilation.assets[entry]) {
23
- const content = compilation.assets[entry].source().toString();
24
- compilation.assets[entry] = new webpack_sources_1.ConcatSource(this.wrapFunction(content));
23
+ const source = compilation.assets[entry];
24
+ compilation.assets[entry] = new webpack_sources_1.ConcatSource(`
25
+ export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
26
+ var org_app_require = $app_require$;
27
+
28
+ (function(global, globalThis, window, $app_exports$, $app_evaluate$){
29
+ var setTimeout = global.setTimeout;
30
+ var setInterval = global.setInterval;
31
+ var clearTimeout = global.clearTimeout;
32
+ var clearInterval = global.clearInterval;
33
+ var $app_require$ = global.$app_require$ || org_app_require
34
+
35
+ var createPageHandler = function() {
36
+ return `, source, `
37
+ }
38
+
39
+ return createPageHandler();
40
+ })(global, globalThis, window, $app_exports$, $app_evaluate$)
41
+ }`);
25
42
  }
26
43
  });
27
44
  }
28
- wrapFunction(code) {
29
- return `
30
- export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
31
- var org_app_require = $app_require$;
32
-
33
- (function(global, globalThis, window, $app_exports$, $app_evaluate$){
34
- var setTimeout = global.setTimeout;
35
- var setInterval = global.setInterval;
36
- var clearTimeout = global.clearTimeout;
37
- var clearInterval = global.clearInterval;
38
- var $app_require$ = global.$app_require$ || org_app_require
39
-
40
- var createPageHandler = function() {
41
- return ${code}
42
- }
43
-
44
- return createPageHandler();
45
- })(global, globalThis, window, $app_exports$, $app_evaluate$)
46
- }`;
47
- }
48
45
  }
49
46
  exports.default = WrapPlugin;
@@ -0,0 +1,3 @@
1
+ import { LoaderContext } from 'webpack';
2
+ declare function splitMap(this: LoaderContext<any>, source: string, map: any): void;
3
+ export default splitMap;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ const path_1 = __importDefault(require("path"));
8
+ function splitMap(source, map) {
9
+ const enterFilePath = this.resourcePath;
10
+ // 获取当前文件夹和文件名
11
+ const dirName = path_1.default.dirname(enterFilePath);
12
+ const fileName = path_1.default.basename(enterFilePath);
13
+ // 取到对应的map文件内容
14
+ const mapFilePath = path_1.default.join(dirName, fileName + '.map');
15
+ if (fs_1.default.existsSync(mapFilePath)) {
16
+ map = fs_1.default.readFileSync(mapFilePath, { encoding: 'utf-8' });
17
+ }
18
+ this.callback(null, source, map && JSON.parse(map));
19
+ }
20
+ exports.default = splitMap;
@@ -1,7 +1,6 @@
1
1
  import { IFileLaneConfig } from 'file-lane';
2
2
  import IJavascriptCompileOption from '../compiler/javascript/interface/IJavascriptCompileOption';
3
3
  import AppUxLoader from '../loader/ux/AppUxLoader';
4
- import ImageCompressLoader from '../loader/ux/ImageCompressLoader';
5
4
  import JsLoader from '../loader/ux/JsLoader';
6
5
  import UxLoader from '../loader/ux/UxLoader';
7
6
  declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
@@ -22,10 +21,6 @@ declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
22
21
  test: RegExp[];
23
22
  loader: (typeof JsLoader)[];
24
23
  exclude?: undefined;
25
- } | {
26
- test: RegExp[];
27
- loader: (typeof ImageCompressLoader)[];
28
- exclude: RegExp[];
29
24
  })[];
30
25
  };
31
26
  preWorks: import("file-lane/lib/interface/IFileLaneConfig").PreWork<IJavascriptCompileOption>[];
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = __importDefault(require("path"));
7
7
  const AppUxLoader_1 = __importDefault(require("../loader/ux/AppUxLoader"));
8
- const ImageCompressLoader_1 = __importDefault(require("../loader/ux/ImageCompressLoader"));
9
8
  const JsLoader_1 = __importDefault(require("../loader/ux/JsLoader"));
10
9
  const PngLoader_1 = __importDefault(require("../loader/ux/PngLoader"));
11
10
  const UxLoader_1 = __importDefault(require("../loader/ux/UxLoader"));
@@ -34,11 +33,6 @@ class UxConfig {
34
33
  {
35
34
  test: [/.+\.9.png/],
36
35
  loader: [PngLoader_1.default]
37
- },
38
- {
39
- test: [/.+\.(png|jpg|jpeg|gif)/],
40
- loader: [ImageCompressLoader_1.default],
41
- exclude: [/.+\.9.png/]
42
36
  }
43
37
  ]
44
38
  };
@@ -132,7 +132,8 @@ UxFollowWorks.copyResource = (context, config, compilerOption) => __awaiter(void
132
132
  'md',
133
133
  'ux',
134
134
  'mix',
135
- 'DS_Store'
135
+ 'DS_Store',
136
+ 'map'
136
137
  ];
137
138
  const excludeReg = `\.(${excludeExtList.join('|')})$`;
138
139
  FileUtil_1.default.copyFiles(path_1.default.join(projectPath, sourceRoot), path_1.default.join(projectPath, outputPath), new RegExp(excludeReg));
@@ -90,6 +90,7 @@ class UxLoaderUtils {
90
90
  // 区分页面组件和子组件
91
91
  const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
92
92
  const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
93
+ // script代码放在第三个位置不能变化,影响更新source map
93
94
  return isAppUx
94
95
  ? [
95
96
  `${appImport.join('\n')}`,
@@ -111,8 +112,8 @@ class UxLoaderUtils {
111
112
  `}`
112
113
  ];
113
114
  };
114
- const { targetTree, mapList } = new UxToTypescript_1.default(options, project, integrateFunction, compilerOption).translate(parserResult.ast, []);
115
- const { code, sourcemap } = new generator_1.TypescriptGenerator().generate({
115
+ const { targetTree, mapList, sourceMap } = yield new UxToTypescript_1.default(options, project, integrateFunction, compilerOption).translate(parserResult.ast, []);
116
+ const { code } = new generator_1.TypescriptGenerator().generate({
116
117
  sourceFilePath: fullName,
117
118
  targetFilePath: newFileName,
118
119
  ast: targetTree,
@@ -126,8 +127,8 @@ class UxLoaderUtils {
126
127
  content: code
127
128
  },
128
129
  {
129
- path: FileUtil_1.default.updatePath(filePath, `${name}.map.js`),
130
- content: sourcemap
130
+ path: FileUtil_1.default.updatePath(filePath, `${name}.js.map`),
131
+ content: sourceMap.toString()
131
132
  }
132
133
  ],
133
134
  logs
@@ -292,7 +293,7 @@ class UxLoaderUtils {
292
293
  // 页面组件添加ViewModel处理代码
293
294
  appScriptTree.addStatements(UxLoaderUtils.contenAccess);
294
295
  }
295
- return `function __scriptModule__(module, exports, $app_require$) {\t${appScriptTree.getFullText()}}`;
296
+ return `function __scriptModule__(module, exports, $app_require$) {\t${appScriptTree.getFullText()}\n}`;
296
297
  }
297
298
  static getReturnType(isPageUx) {
298
299
  return isPageUx ? `$app_exports$['entry'] =` : 'module.exports = ';
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.2-dev.2",
3
+ "version": "2.0.2-dev.4",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
7
7
  ],
8
- "author": "徐俊杰 <xujunjie1@xiaomi.com>",
9
8
  "homepage": "",
10
9
  "license": "ISC",
11
10
  "main": "lib/index.js",
@@ -16,26 +15,21 @@
16
15
  "files": [
17
16
  "lib"
18
17
  ],
19
- "repository": {
20
- "type": "git",
21
- "url": "ssh://xujunjie1@git.mioffice.cn:29418/vela/aiot-toolkit"
22
- },
23
18
  "scripts": {
24
19
  "test": "node ./__tests__/aiotpack.test.js"
25
20
  },
26
21
  "dependencies": {
27
- "@aiot-toolkit/generator": "2.0.2-dev.2",
28
- "@aiot-toolkit/parser": "2.0.2-dev.2",
22
+ "@aiot-toolkit/generator": "2.0.2-dev.4",
23
+ "@aiot-toolkit/parser": "2.0.2-dev.4",
29
24
  "@hap-toolkit/aaptjs": "^2.0.0",
30
25
  "babel-loader": "^9.1.3",
31
26
  "del": "^4.1.0",
32
27
  "fast-glob": "^3.3.2",
33
- "file-lane": "2.0.2-dev.2",
28
+ "file-lane": "2.0.2-dev.4",
34
29
  "file-loader": "^6.2.0",
35
30
  "fs-extra": "^11.2.0",
36
31
  "jsrsasign": "^7.2.2",
37
32
  "jszip": "^3.10.1",
38
- "sharp": "^0.33.2",
39
33
  "url-loader": "^4.1.1",
40
34
  "webpack": "^5.89.0",
41
35
  "webpack-sources": "^3.2.3"
@@ -44,5 +38,5 @@
44
38
  "@types/jsrsasign": "^10.5.12",
45
39
  "@types/webpack-sources": "^3.2.3"
46
40
  },
47
- "gitHead": "4979839c27a3477f7e72f1f1ed167200bc1d48b5"
41
+ "gitHead": "534fdc7c6f018623c05499bf9add8db813ef8660"
48
42
  }
@@ -1,9 +0,0 @@
1
- import { IFileParam, ILoader } from 'file-lane';
2
- /**
3
- * 图片压缩
4
- */
5
- declare class ImageCompressLoader implements ILoader {
6
- parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
7
- private compressImages;
8
- }
9
- export default ImageCompressLoader;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const path_1 = __importDefault(require("path"));
16
- const sharp_1 = __importDefault(require("sharp"));
17
- /**
18
- * 图片压缩
19
- */
20
- class ImageCompressLoader {
21
- parser(files) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const result = [];
24
- for (const file of files) {
25
- const { path, content } = file;
26
- if (content instanceof Buffer) {
27
- const newContent = yield this.compressImages(path, content);
28
- result.push({
29
- path,
30
- content: newContent
31
- });
32
- }
33
- }
34
- return result;
35
- });
36
- }
37
- compressImages(path, content, minSize = 1024 * 10) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- if (content.length < minSize) {
40
- return content;
41
- }
42
- let result = null;
43
- const quality = 80;
44
- const ext = path_1.default.parse(path).ext;
45
- switch (ext) {
46
- case '.png':
47
- result = yield (0, sharp_1.default)(content).png({ quality }).toBuffer();
48
- break;
49
- case '.jpg':
50
- case '.jpeg':
51
- result = yield (0, sharp_1.default)(content).jpeg({ quality }).toBuffer();
52
- break;
53
- case '.gif':
54
- result = yield (0, sharp_1.default)(content, { animated: true }).gif({ interFrameMaxError: 8 }).toBuffer();
55
- break;
56
- case '.webp':
57
- const metadata = yield (0, sharp_1.default)(content).metadata();
58
- result = yield (0, sharp_1.default)(content, metadata.pages ? { animated: true } : undefined)
59
- .webp({ quality })
60
- .toBuffer();
61
- break;
62
- default:
63
- return content;
64
- }
65
- if (result && result.length < content.length) {
66
- return result;
67
- }
68
- return content;
69
- });
70
- }
71
- }
72
- ;
73
- ImageCompressLoader.raw = true;
74
- exports.default = ImageCompressLoader;