xhs-mp-compiler-cli 1.1.0 → 1.1.2

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 (32) hide show
  1. package/dist/bin/xhs-mp-cli-build.js +2 -2
  2. package/dist/bin/xhs-mp-cli-dev.js +3 -3
  3. package/dist/compilerCP.js +3 -3
  4. package/dist/config/constant.config.d.ts +20 -0
  5. package/dist/config/constant.config.js +25 -5
  6. package/dist/config/dir.config.d.ts +3 -0
  7. package/dist/config/dir.config.js +16 -0
  8. package/dist/index.d.ts +84 -1
  9. package/dist/index.js +452 -3
  10. package/dist/packs/mp-pack/index.js +1 -1
  11. package/dist/{dev-server → packs/webpack/dev-server}/index.d.ts +1 -1
  12. package/dist/{dev-server → packs/webpack/dev-server}/index.js +1 -1
  13. package/dist/packs/webpack/index.js +1 -1
  14. package/dist/presets/common.js +13 -11
  15. package/dist/presets/configs/minigame/service/index.js +1 -1
  16. package/dist/presets/configs/miniprogram/render/index.js +6 -5
  17. package/dist/presets/configs/miniprogram/service/index.js +7 -7
  18. package/dist/presets/index.js +1 -1
  19. package/dist/utils/file.d.ts +2 -0
  20. package/dist/utils/file.js +67 -0
  21. package/dist/utils/project.d.ts +27 -0
  22. package/dist/utils/project.js +164 -0
  23. package/dist/utils/utils.d.ts +2 -0
  24. package/dist/utils/utils.js +13 -0
  25. package/dist/utils/zip.d.ts +28 -0
  26. package/dist/utils/zip.js +287 -0
  27. package/package.json +11 -5
  28. /package/dist/{dev-server → packs/webpack/dev-server}/lib/ensurePort.d.ts +0 -0
  29. /package/dist/{dev-server → packs/webpack/dev-server}/lib/ensurePort.js +0 -0
  30. /package/dist/{dev-server → packs/webpack/dev-server}/lib/openBrowser.d.ts +0 -0
  31. /package/dist/{dev-server → packs/webpack/dev-server}/lib/openBrowser.js +0 -0
  32. /package/dist/{dev-server → packs/webpack/dev-server}/lib/openChrome.applescript +0 -0
package/dist/index.js CHANGED
@@ -1,5 +1,454 @@
1
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
+ };
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCompiler = void 0;
4
- var packs_1 = require("./packs");
5
- Object.defineProperty(exports, "createCompiler", { enumerable: true, get: function () { return packs_1.createCompiler; } });
15
+ exports.Compiler = exports.getProcessCompilerClass = exports.COMPILE_ENTRY = void 0;
16
+ const constant_config_1 = require("./config/constant.config");
17
+ Object.defineProperty(exports, "COMPILE_ENTRY", { enumerable: true, get: function () { return constant_config_1.COMPILE_ENTRY; } });
18
+ const xhs_mp_project_1 = require("xhs-mp-project");
19
+ const events_1 = __importDefault(require("events"));
20
+ const fs_extra_1 = __importDefault(require("fs-extra"));
21
+ const path_1 = __importDefault(require("path"));
22
+ const utils_1 = require("./utils/utils");
23
+ const zip_1 = require("./utils/zip");
24
+ const project_1 = require("./utils/project");
25
+ const dir_config_1 = require("./config/dir.config");
26
+ const compiler_1 = require("./compiler");
27
+ Object.defineProperty(exports, "getProcessCompilerClass", { enumerable: true, get: function () { return compiler_1.getProcessCompilerClass; } });
28
+ class Compiler extends events_1.default {
29
+ constructor(props) {
30
+ super();
31
+ this.compilerImplMap = {};
32
+ this.initSimulatorCompiler = compiler => {
33
+ compiler.on('buildStart', data => {
34
+ this.emit('buildStart', data);
35
+ });
36
+ compiler.on('buildSuccess', data => {
37
+ this.emit('buildSuccess', data);
38
+ });
39
+ compiler.on('buildError', data => {
40
+ this.emit('buildError', data);
41
+ });
42
+ compiler.on('compileFinishWhenFileChange', data => {
43
+ this.emit('compileFinishWhenFileChange', data);
44
+ });
45
+ compiler.on('emitCompileStats', data => {
46
+ this.emit('emitCompileStats', data);
47
+ });
48
+ compiler.on('unexpectedExit', data => {
49
+ this.emit('unexpectedExit', data);
50
+ });
51
+ };
52
+ this.initBuildCompiler = compiler => {
53
+ compiler.on('compilePercent', data => {
54
+ this.emit('compilePercent', data);
55
+ });
56
+ compiler.on('emitCompileStats', data => {
57
+ this.emit('emitCompileStats', data);
58
+ });
59
+ };
60
+ this.getComilerImpl = (entryType = constant_config_1.COMPILE_ENTRY.simulator) => {
61
+ const compilerType = this.getCompilerType(entryType);
62
+ if (!this.compilerImplMap[compilerType]) {
63
+ this.compilerImplMap[compilerType] = this.createCompilerImpl(entryType);
64
+ if (entryType === constant_config_1.COMPILE_ENTRY.simulator) {
65
+ this.initSimulatorCompiler(this.compilerImplMap[compilerType]);
66
+ }
67
+ else {
68
+ this.initBuildCompiler(this.compilerImplMap[compilerType]);
69
+ }
70
+ }
71
+ return this.compilerImplMap[compilerType];
72
+ };
73
+ const { logger } = props;
74
+ this.logger = logger || console;
75
+ this.compilerProps = props;
76
+ this.project = this.createProject(props);
77
+ this.projectPath = this.project.projectPath;
78
+ }
79
+ createProject(props) {
80
+ const { projectPath, project } = props;
81
+ return (project ||
82
+ new xhs_mp_project_1.Project({
83
+ projectPath
84
+ }));
85
+ }
86
+ getCompilerDir() {
87
+ let compileDirPath;
88
+ let compileCachePath;
89
+ const { compileDir } = this.compilerProps;
90
+ if (compileDir) {
91
+ compileDirPath = path_1.default.join(compileDir, 'xhs-mp-baba');
92
+ compileCachePath = path_1.default.join(compileDir, 'xhs-compile-cache');
93
+ }
94
+ else {
95
+ compileDirPath = dir_config_1.mpCompileDirPath;
96
+ compileCachePath = dir_config_1.mpCompileCachePath;
97
+ }
98
+ return {
99
+ mpCompileDirPath: compileDirPath,
100
+ mpCompileCachePath: compileCachePath
101
+ };
102
+ }
103
+ // 使用的编译目标包类型
104
+ getUsingPackageType() {
105
+ return __awaiter(this, arguments, void 0, function* (entryType = constant_config_1.COMPILE_ENTRY.simulator) {
106
+ var _a, _b;
107
+ const { libFeatures } = this.compilerProps;
108
+ let enableV1 = false;
109
+ let enableV2 = true;
110
+ let enableVDom = false;
111
+ const settings = this.project.settings || {};
112
+ const isUpload = entryType === constant_config_1.COMPILE_ENTRY.upload;
113
+ if (this.project.appMode === constant_config_1.MiniMode.minigame) {
114
+ enableV1 = true;
115
+ enableV2 = false;
116
+ enableVDom = false;
117
+ }
118
+ else if (entryType === constant_config_1.COMPILE_ENTRY.simulator) {
119
+ const supportV2 = (_a = libFeatures === null || libFeatures === void 0 ? void 0 : libFeatures.supportV2) !== null && _a !== void 0 ? _a : true;
120
+ const supportVDom = (_b = libFeatures === null || libFeatures === void 0 ? void 0 : libFeatures.supportVdom) !== null && _b !== void 0 ? _b : true;
121
+ // 模拟器预览模式下,按照基础库是否支持相关功能 + 用户是否勾选进行判断
122
+ enableV2 = supportV2 && settings.enableV2;
123
+ // 开启v2不编译vdom
124
+ enableVDom = !enableV2 && supportVDom && settings.enableVDom;
125
+ // enableVDom = !enableV2 && settings.enableVDom
126
+ enableV1 = !enableV2;
127
+ }
128
+ else {
129
+ // 上传模式下按照勾选开启
130
+ enableVDom = settings.enableVDom;
131
+ enableV2 = settings.enableV2;
132
+ enableV1 = true;
133
+ }
134
+ return {
135
+ enableV1,
136
+ enableV2,
137
+ enableVDom
138
+ };
139
+ });
140
+ }
141
+ // 根据使用的场景或者配置,采用不同的compiler类型
142
+ getCompilerType(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
143
+ const isGame = this.project.appMode === constant_config_1.MiniMode.minigame;
144
+ const settings = this.project.projectJsonContent.setting || {};
145
+ // 使用旧编译
146
+ if (isGame || !settings.useNewCompiler) {
147
+ return entryType === constant_config_1.COMPILE_ENTRY.simulator ? constant_config_1.COMPILER_TYPE.legacy_dev : constant_config_1.COMPILER_TYPE.legacy_build;
148
+ }
149
+ // 使用新编译
150
+ return entryType === constant_config_1.COMPILE_ENTRY.simulator
151
+ ? constant_config_1.COMPILER_TYPE.dev
152
+ : entryType === constant_config_1.COMPILE_ENTRY.upload
153
+ ? constant_config_1.COMPILER_TYPE.legacy_build
154
+ : constant_config_1.COMPILER_TYPE.build;
155
+ }
156
+ getDistDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
157
+ const { mpCompileDirPath } = this.getCompilerDir();
158
+ const compilerType = this.getCompilerType(entryType);
159
+ const basename = path_1.default.basename(this.project.projectPath);
160
+ const hash = (0, utils_1.getMd5)(this.project.projectPath).slice(0, 8);
161
+ const distDir = path_1.default.join(path_1.default.resolve(mpCompileDirPath, `${basename}_${hash}`), compilerType);
162
+ fs_extra_1.default.ensureDirSync(distDir);
163
+ return distDir;
164
+ }
165
+ removeDistDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
166
+ const distDir = this.getDistDir(entryType);
167
+ if (fs_extra_1.default.existsSync(distDir)) {
168
+ fs_extra_1.default.removeSync(distDir);
169
+ }
170
+ }
171
+ getCacheDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
172
+ const { mpCompileCachePath } = this.getCompilerDir();
173
+ const compilerType = this.getCompilerType(entryType);
174
+ const basename = path_1.default.basename(this.project.projectPath);
175
+ const hash = (0, utils_1.getMd5)(this.project.projectPath).slice(0, 8);
176
+ const distDir = path_1.default.join(path_1.default.resolve(mpCompileCachePath, `${basename}_${hash}`), compilerType);
177
+ fs_extra_1.default.ensureDirSync(distDir);
178
+ return distDir;
179
+ }
180
+ removeCacheDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
181
+ const cacheDir = this.getCacheDir(entryType);
182
+ if (fs_extra_1.default.existsSync(cacheDir)) {
183
+ fs_extra_1.default.removeSync(cacheDir);
184
+ }
185
+ }
186
+ createCompilerImpl(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
187
+ const { nodeJsPath, mpDevJsonPath } = this.compilerProps;
188
+ const { mpCompileDirPath } = this.getCompilerDir();
189
+ const distDir = this.getDistDir(entryType);
190
+ const cacheDir = this.getCacheDir(entryType);
191
+ const compilerType = this.getCompilerType(entryType);
192
+ const packMode = compilerType === constant_config_1.COMPILER_TYPE.legacy_dev || compilerType === constant_config_1.COMPILER_TYPE.legacy_build
193
+ ? 'webpack'
194
+ : 'mp-pack';
195
+ const options = {
196
+ packMode,
197
+ projectPath: this.project.projectPath,
198
+ appMode: this.project.appMode,
199
+ extJsonPath: this.project.extJsonDir,
200
+ platform: 'xhs',
201
+ distDir,
202
+ cacheDirectory: cacheDir
203
+ };
204
+ this.removeDistDir(entryType);
205
+ this.removeCacheDir(entryType);
206
+ const CompilerClass = (0, compiler_1.getProcessCompilerClass)(compilerType);
207
+ const compilerImpl = new CompilerClass(options, {
208
+ logger: this.logger,
209
+ nodeJsPath
210
+ });
211
+ return compilerImpl;
212
+ }
213
+ makePkgsReady(config) {
214
+ return __awaiter(this, void 0, void 0, function* () {
215
+ const entryType = constant_config_1.COMPILE_ENTRY.simulator;
216
+ const compilerImpl = this.getComilerImpl(entryType);
217
+ yield compilerImpl.makePkgsReady(config);
218
+ });
219
+ }
220
+ reCompilePkgs(config) {
221
+ return __awaiter(this, void 0, void 0, function* () {
222
+ const entryType = constant_config_1.COMPILE_ENTRY.simulator;
223
+ const compilerImpl = this.getComilerImpl(entryType);
224
+ yield compilerImpl.reCompilePkgs(config);
225
+ });
226
+ }
227
+ compileProject(config) {
228
+ return __awaiter(this, void 0, void 0, function* () {
229
+ var _a, _b, _c;
230
+ try {
231
+ const { entryType, compressJs, enableSourcemap, enableV2, enableV1, enableVDom } = config;
232
+ this.emit('compile-project-start');
233
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.log('Compile project...');
234
+ const compilerImpl = this.getComilerImpl(entryType);
235
+ yield compilerImpl.build({
236
+ compressJs,
237
+ enableSourcemap,
238
+ enableV2,
239
+ enableV1,
240
+ enableVDom
241
+ });
242
+ this.emit('compile-project-done');
243
+ (_b = this.logger) === null || _b === void 0 ? void 0 : _b.log('Compile project done');
244
+ }
245
+ catch (stats) {
246
+ let error;
247
+ if (stats instanceof Error) {
248
+ error = stats;
249
+ }
250
+ else {
251
+ const { errors } = stats || {};
252
+ error = new Error(errors.join('\n\n'));
253
+ }
254
+ (_c = this.logger) === null || _c === void 0 ? void 0 : _c.log('Compile project failed', error);
255
+ this.emit('compile-project-fail', error);
256
+ throw error;
257
+ }
258
+ });
259
+ }
260
+ compileAndZip(opts) {
261
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
262
+ const { can_upload_ext_json, upload_app_id, entryType } = opts;
263
+ try {
264
+ const appJsonContent = this.project.appJsonContent;
265
+ const settings = this.project.settings || {};
266
+ let subPackages = appJsonContent.subPackages || appJsonContent.subpackages || [];
267
+ const formatGameAppJSON = this.project.formatGameAppJSON;
268
+ subPackages =
269
+ this.project.appMode === constant_config_1.MiniMode.miniprogram ? subPackages : formatGameAppJSON(subPackages);
270
+ const { enableV2, enableV1, enableVDom } = yield this.getUsingPackageType(entryType);
271
+ let compressJs = false;
272
+ let enableSourcemap = true;
273
+ if (entryType === constant_config_1.COMPILE_ENTRY.upload || entryType === constant_config_1.COMPILE_ENTRY.preview) {
274
+ compressJs = true;
275
+ enableSourcemap = false;
276
+ }
277
+ else if (settings.hasOwnProperty('minified')) {
278
+ compressJs = settings.minified;
279
+ }
280
+ const buildConfig = {
281
+ entryType,
282
+ compressJs,
283
+ enableSourcemap,
284
+ enableV2,
285
+ enableV1,
286
+ enableVDom
287
+ };
288
+ // 编译
289
+ this.emit('compile-and-zip-status', { status: 'build-start' });
290
+ yield this.compileProject(buildConfig);
291
+ this.emit('compile-and-zip-status', { status: 'build-done' });
292
+ // 生成zip
293
+ this.emit('compile-and-zip-status', { status: 'zip-start' });
294
+ let entryZips = [];
295
+ if (entryType === constant_config_1.COMPILE_ENTRY.preview || entryType === constant_config_1.COMPILE_ENTRY.upload) {
296
+ entryZips = [
297
+ this.zipWithFullPackage(opts, subPackages, 'v0'),
298
+ this.zipWithSubPackage(opts, subPackages, 'v1'),
299
+ // 小程序模式有v2包
300
+ enableV2 && this.zipWithSubPackage(opts, subPackages, 'v2')
301
+ ];
302
+ }
303
+ else {
304
+ // 真机调试
305
+ // eslint-disable-next-line no-lonely-if
306
+ if (!subPackages.length) {
307
+ // 真机调试整包zip内产物文件需要放在appid目录下
308
+ entryZips = [this.zipWithFullPackageWithAppId(opts, subPackages, 'v0')];
309
+ }
310
+ else {
311
+ // eslint-disable-next-line no-lonely-if
312
+ if (enableV2) {
313
+ entryZips = [this.zipWithSubPackage(opts, subPackages, 'v2')];
314
+ }
315
+ else {
316
+ entryZips = [this.zipWithSubPackage(opts, subPackages, 'v1')];
317
+ }
318
+ }
319
+ }
320
+ const zipTask = yield Promise.all(entryZips.filter(Boolean));
321
+ const zipResult = zipTask.flat(2);
322
+ this.emit('compile-and-zip-status', { status: 'zip-done' });
323
+ // change ext
324
+ if (entryType === constant_config_1.COMPILE_ENTRY.preview || entryType === constant_config_1.COMPILE_ENTRY.upload) {
325
+ this.project.changeExtJsonPermission(!!can_upload_ext_json);
326
+ }
327
+ resolve(zipResult);
328
+ }
329
+ catch (error) {
330
+ reject(error);
331
+ }
332
+ }));
333
+ }
334
+ zipWithFullPackageWithAppId(opts_1) {
335
+ return __awaiter(this, arguments, void 0, function* (opts, subPackages = [], type) {
336
+ const { entryType } = opts;
337
+ const buildDir = this.getDistDir(entryType);
338
+ const distFullZip = path_1.default.resolve(buildDir, 'v0-full-pack.zip');
339
+ const srcDirPath = path_1.default.resolve(buildDir, !subPackages.length ? 'v1' : 'v0'); // 如果没有开启分包,则把v1包当作v0包
340
+ return (0, zip_1.genZip)(srcDirPath, distFullZip, this.project.projectAppId);
341
+ });
342
+ }
343
+ /* 使用v0的入口,zip整包 */
344
+ zipWithFullPackage(opts_1) {
345
+ return __awaiter(this, arguments, void 0, function* (opts, subPackages = [], type) {
346
+ const project = this.project;
347
+ const { upload_app_id, can_upload_ext_json, pkgInfo, entryType } = opts;
348
+ const buildDir = this.getDistDir(entryType);
349
+ const appendFile = [];
350
+ const appendBuffer = [];
351
+ appendFile.push(project.projectJsonPath); // zip添加project.config.json
352
+ /* 是否需要上传ext.json */
353
+ if (can_upload_ext_json && fs_extra_1.default.existsSync(project.extJsonPath)) {
354
+ appendFile.push(project.extJsonPath);
355
+ }
356
+ if (pkgInfo) {
357
+ /* 是否需要额外添加pkgInfo.json信息 */
358
+ const content = { version: pkgInfo.version };
359
+ const contentStr = JSON.stringify(content);
360
+ appendBuffer.push({
361
+ name: 'pkgInfo.json',
362
+ buffer: Buffer.from(contentStr, 'utf-8')
363
+ });
364
+ }
365
+ const zipConfig = {
366
+ outputDir: path_1.default.resolve(buildDir, `${type}-full-pack.zip`), // 输出的路径
367
+ type,
368
+ inputDir: path_1.default.resolve(buildDir, !subPackages.length ? 'v1' : 'v0' // 如果没有开启分包,则把v1包当作v0包
369
+ ), // 输入的路径
370
+ ignore: [],
371
+ prefix: upload_app_id,
372
+ appendFile,
373
+ appendBuffer,
374
+ meta: {
375
+ root: ''
376
+ }
377
+ };
378
+ return (0, project_1.zipFactory)(zipConfig);
379
+ });
380
+ }
381
+ /* 使用v1的入口。zip主包和分包 */
382
+ zipWithSubPackage(opts, subPackages, type) {
383
+ return __awaiter(this, void 0, void 0, function* () {
384
+ const project = this.project;
385
+ const { can_upload_ext_json, pkgInfo, entryType } = opts;
386
+ const isRemoteDebug = entryType === constant_config_1.COMPILE_ENTRY.remotedebug;
387
+ const appendFile = []; // 额外的文件
388
+ const appendBuffer = [];
389
+ appendFile.push(project.projectJsonPath); // zip添加project.config.json
390
+ const buildDir = this.getDistDir(entryType);
391
+ const mainEntry = path_1.default.resolve(buildDir, type);
392
+ const mainIgnore = (subPackages || []).map(item => item.root.endsWith('/') ? `${item.root}**` : `${item.root}/**`); // 主包里需要忽略分包的路径
393
+ /* 是否需要上传ext.json */
394
+ if (can_upload_ext_json && fs_extra_1.default.existsSync(project.extJsonPath)) {
395
+ appendFile.push(project.extJsonPath);
396
+ }
397
+ if (pkgInfo) {
398
+ /* 是否需要额外添加pkgInfo.json信息 */
399
+ const content = { version: pkgInfo.version };
400
+ const contentStr = JSON.stringify(content);
401
+ appendBuffer.push({
402
+ name: 'pkgInfo.json',
403
+ buffer: Buffer.from(contentStr, 'utf-8')
404
+ });
405
+ }
406
+ /* 分包的zip配置 */
407
+ const zipConfig = [
408
+ {
409
+ outputDir: path_1.default.resolve(buildDir, `${type}-main-pack.zip`), // 输出的路径
410
+ type,
411
+ inputDir: mainEntry, // 输入的路径
412
+ ignore: mainIgnore,
413
+ prefix: '',
414
+ appendFile,
415
+ appendBuffer,
416
+ meta: {
417
+ root: '/'
418
+ }
419
+ },
420
+ ...(subPackages || []).map((item, index) => {
421
+ const pkgRoot = item.root.replace(/\//g, constant_config_1.PKG_ROOT_SEP);
422
+ return {
423
+ outputDir: path_1.default.resolve(buildDir, `${type}-sub-pack-${isRemoteDebug ? pkgRoot : index}.zip`),
424
+ type,
425
+ inputDir: path_1.default.resolve(buildDir, type, item.root),
426
+ ignore: [],
427
+ prefix: `${item.root}`,
428
+ meta: {
429
+ root: item.root
430
+ }
431
+ };
432
+ })
433
+ ];
434
+ return Promise.all(zipConfig.map(config => (0, project_1.zipFactory)(config)));
435
+ });
436
+ }
437
+ close(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
438
+ const compilerType = this.getCompilerType(entryType);
439
+ const compiler = this.compilerImplMap[compilerType];
440
+ if (compiler) {
441
+ compiler.close();
442
+ }
443
+ }
444
+ kill(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
445
+ const compilerType = this.getCompilerType(entryType);
446
+ const compiler = this.compilerImplMap[compilerType];
447
+ if (!compiler) {
448
+ return;
449
+ }
450
+ compiler.kill();
451
+ delete this.compilerImplMap[entryType];
452
+ }
453
+ }
454
+ exports.Compiler = Compiler;
@@ -7,7 +7,7 @@ exports.createCompiler = void 0;
7
7
  const presets_1 = require("../../presets");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const xhs_mp_pack_1 = require("xhs-mp-pack");
10
- const dev_server_1 = __importDefault(require("../../dev-server"));
10
+ const dev_server_1 = __importDefault(require("../webpack/dev-server"));
11
11
  const createCompiler = (startConfig) => {
12
12
  const { action, enableDevServer } = startConfig;
13
13
  const mppack = new xhs_mp_pack_1.MPPack(startConfig);
@@ -1,3 +1,3 @@
1
- import { IPresetOptions } from '../types';
1
+ import { IPresetOptions } from '../../../types';
2
2
  declare const devServer: (config: IPresetOptions) => Promise<void>;
3
3
  export default devServer;
@@ -16,7 +16,7 @@ const path_1 = __importDefault(require("path"));
16
16
  const webpack_1 = __importDefault(require("webpack"));
17
17
  const ensurePort_1 = __importDefault(require("./lib/ensurePort"));
18
18
  const openBrowser_1 = __importDefault(require("./lib/openBrowser"));
19
- const presets_1 = require("../presets");
19
+ const presets_1 = require("../../../presets");
20
20
  const devServer = (config) => __awaiter(void 0, void 0, void 0, function* () {
21
21
  const { packSetting } = config;
22
22
  const { devServerPort, distDir } = packSetting;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createCompiler = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const dev_server_1 = __importDefault(require("../../dev-server"));
9
+ const dev_server_1 = __importDefault(require("./dev-server"));
10
10
  const projectConfig_1 = require("../../utils/projectConfig");
11
11
  const common_1 = require("../../utils/common");
12
12
  const types_1 = require("../../types");
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = __importDefault(require("path"));
7
- const types_1 = require("../types");
8
7
  const presetCommon = (chain, options) => {
9
8
  const { packSetting, project } = options;
10
9
  const { env, watch, enableSourcemap, cacheDirectory } = packSetting;
@@ -32,15 +31,18 @@ const presetCommon = (chain, options) => {
32
31
  chain.devtool(enableSourcemap ? 'source-map' : false);
33
32
  // @ts-ignore
34
33
  chain.target(['web', 'es5']);
35
- chain.cache(env === types_1.ENV.production
36
- ? false
37
- : {
38
- type: 'filesystem',
39
- cacheDirectory: cacheDirectory || path_1.default.join(__dirname, '../../node_modules/.cache'),
40
- version: project.miniprogramDir,
41
- buildDependencies: {
42
- config: [path_1.default.join(project.miniprogramDir, 'app.json')],
43
- },
44
- });
34
+ // chain.cache(
35
+ // env === ENV.production
36
+ // ? false
37
+ // : {
38
+ // type: 'filesystem',
39
+ // cacheDirectory:
40
+ // cacheDirectory || path.join(__dirname, '../../node_modules/.cache'),
41
+ // version: project.miniprogramDir,
42
+ // buildDependencies: {
43
+ // config: [path.join(project.miniprogramDir, 'app.json')],
44
+ // },
45
+ // },
46
+ // )
45
47
  };
46
48
  exports.default = presetCommon;
@@ -18,9 +18,9 @@ const presetService = (chain, options) => {
18
18
  }
19
19
  });
20
20
  chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
21
- chain.resolve.plugin('ResolveLimitPlugin').use(resolveLimitPlugin_1.default, [options]);
22
21
  chain.plugin('ServiceEntryPlugin').use(serviceEntryPlugin_1.default, [options]);
23
22
  chain.plugin('ServiceChunkPlugin').use(serviceChunkPlugin_1.default, [options]);
23
+ chain.resolve.plugin('ResolveLimitPlugin').use(resolveLimitPlugin_1.default, [options]);
24
24
  chain.optimization
25
25
  .runtimeChunk({
26
26
  name: 'runtime'
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.presetRender = exports.getRenderEntry = void 0;
7
+ const path_1 = __importDefault(require("path"));
7
8
  const css_1 = __importDefault(require("../../../../utils/css"));
8
9
  const getSuffixName_1 = require("../../../../utils/getSuffixName");
9
10
  const sjsEntryPlugin_1 = __importDefault(require("./sjsEntryPlugin"));
@@ -16,7 +17,7 @@ const getRenderEntry = (options) => () => (Object.assign(Object.assign({}, (0, r
16
17
  exports.getRenderEntry = getRenderEntry;
17
18
  const presetRender = (chain, options) => {
18
19
  const { packSetting } = options;
19
- const { enableVDom, env, distDir } = packSetting;
20
+ const { enableVDom, env, distDir, cacheDirectory } = packSetting;
20
21
  const mlReg = new RegExp(`.${(0, getSuffixName_1.getMlSuffixName)()}$`);
21
22
  const cssReg = new RegExp(`.${(0, getSuffixName_1.getCssSuffixName)()}$`);
22
23
  const isProd = env === types_1.ENV.production;
@@ -28,10 +29,10 @@ const presetRender = (chain, options) => {
28
29
  libraryTarget: 'umd',
29
30
  uniqueName: 'MpRender',
30
31
  },
31
- // cache: {
32
- // type: 'filesystem',
33
- // cacheDirectory: packSetting.cacheDirectory,
34
- // },
32
+ cache: {
33
+ type: 'filesystem',
34
+ cacheDirectory: path_1.default.join(cacheDirectory, 'render'),
35
+ },
35
36
  module: {
36
37
  rule: {
37
38
  ml: {
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.presetService = exports.getServiceEntry = void 0;
7
+ const path_1 = __importDefault(require("path"));
7
8
  const xhs_mp_pack_1 = require("xhs-mp-pack");
8
9
  const serviceChunkPlugin_1 = __importDefault(require("./serviceChunkPlugin"));
9
10
  const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
@@ -41,19 +42,18 @@ const appendV1Entry = (options, entries) => {
41
42
  };
42
43
  const presetService = (chain, options) => {
43
44
  const { packSetting } = options;
44
- const { env, distDir } = packSetting;
45
- const isProd = env === xhs_mp_pack_1.ENV.production;
45
+ const { env, distDir, cacheDirectory } = packSetting;
46
46
  chain.merge({
47
47
  output: {
48
48
  path: distDir,
49
49
  globalObject: 'globalThis',
50
50
  libraryTarget: 'umd',
51
51
  uniqueName: 'MpService',
52
- }
53
- // cache: {
54
- // type: 'filesystem',
55
- // cacheDirectory: cacheDirectory,
56
- // },
52
+ },
53
+ cache: {
54
+ type: 'filesystem',
55
+ cacheDirectory: path_1.default.join(cacheDirectory, 'service'),
56
+ },
57
57
  });
58
58
  chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
59
59
  chain.plugin('ServiceChunkPlugin').use(serviceChunkPlugin_1.default, [options]);
@@ -13,7 +13,7 @@ const assets_1 = require("./configs/miniprogram/assets");
13
13
  const service_1 = require("./configs/miniprogram/service");
14
14
  const render_1 = require("./configs/miniprogram/render");
15
15
  const assets_2 = require("./configs/minigame/assets");
16
- const service_2 = require("./configs/miniprogram/service");
16
+ const service_2 = require("./configs/minigame/service");
17
17
  /**
18
18
  * 小程序编译配置
19
19
  */
@@ -0,0 +1,2 @@
1
+ export declare const fileSize: (size: number) => string;
2
+ export declare const getFolderSize: (folder: string[]) => Promise<number>;