xhs-mp-compiler-cli 2.0.0-beta.3 → 2.0.0

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 (94) hide show
  1. package/dist/bin/xhs-mp-cli-build.js +48 -34
  2. package/dist/bin/xhs-mp-cli-dev.js +44 -44
  3. package/dist/bin/xhs-mp-cli.js +22 -12
  4. package/dist/compiler.d.ts +21 -28
  5. package/dist/compiler.js +327 -327
  6. package/dist/compilerImpl.d.ts +19 -0
  7. package/dist/compilerImpl.js +173 -0
  8. package/dist/config/constant.config.d.ts +24 -0
  9. package/dist/config/constant.config.js +82 -30
  10. package/dist/config/dir.config.js +23 -13
  11. package/dist/index.d.ts +9 -9
  12. package/dist/index.js +454 -408
  13. package/dist/packs/index.d.ts +4 -4
  14. package/dist/packs/index.js +38 -30
  15. package/dist/packs/mp-pack/index.js +38 -30
  16. package/dist/packs/webpack/dev-server/index.js +61 -50
  17. package/dist/packs/webpack/dev-server/lib/ensurePort.js +33 -23
  18. package/dist/packs/webpack/dev-server/lib/openBrowser.js +28 -18
  19. package/dist/packs/webpack/index.d.ts +1 -1
  20. package/dist/packs/webpack/index.js +99 -90
  21. package/dist/packs/webpack/webpack.d.ts +2 -1
  22. package/dist/packs/webpack/webpack.js +81 -63
  23. package/dist/presets/babel.d.ts +0 -1
  24. package/dist/presets/babel.js +64 -58
  25. package/dist/presets/common.js +42 -45
  26. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +50 -40
  27. package/dist/presets/configs/minigame/assets/index.js +62 -52
  28. package/dist/presets/configs/minigame/service/index.js +49 -30
  29. package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +33 -23
  30. package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +2 -2
  31. package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -60
  32. package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +3 -3
  33. package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +39 -29
  34. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +120 -113
  35. package/dist/presets/configs/miniprogram/assets/index.js +45 -43
  36. package/dist/presets/configs/miniprogram/render/component.js +51 -41
  37. package/dist/presets/configs/miniprogram/render/index.d.ts +2 -3
  38. package/dist/presets/configs/miniprogram/render/index.js +85 -68
  39. package/dist/presets/configs/miniprogram/render/render.js +53 -43
  40. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +84 -49
  41. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
  42. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +164 -126
  43. package/dist/presets/configs/miniprogram/service/index.js +82 -65
  44. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +60 -50
  45. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +93 -55
  46. package/dist/presets/index.js +100 -90
  47. package/dist/presets/loaders/mg-entry-loader.js +32 -22
  48. package/dist/presets/loaders/mini-style-loader.js +79 -55
  49. package/dist/presets/loaders/mp-entry-loader.js +149 -140
  50. package/dist/presets/loaders/wxss-loader.js +73 -63
  51. package/dist/presets/plugins/InjectorPlugin.js +23 -13
  52. package/dist/presets/plugins/SourceMapDevToolPlugin.d.ts +1 -0
  53. package/dist/presets/plugins/SourceMapDevToolPlugin.js +23 -0
  54. package/dist/presets/prod.js +88 -78
  55. package/dist/sharedFs.d.ts +2 -0
  56. package/dist/sharedFs.js +24 -0
  57. package/dist/types/index.d.ts +11 -37
  58. package/dist/types/index.js +23 -13
  59. package/dist/utils/{apm/index.d.ts → apm.d.ts} +5 -3
  60. package/dist/utils/apm.js +245 -0
  61. package/dist/utils/cache.d.ts +28 -0
  62. package/dist/utils/cache.js +49 -0
  63. package/dist/utils/common.js +42 -32
  64. package/dist/utils/css.d.ts +1 -1
  65. package/dist/utils/css.js +43 -35
  66. package/dist/utils/depenedHelper.js +95 -85
  67. package/dist/utils/file.js +39 -29
  68. package/dist/utils/loader-utils.js +63 -53
  69. package/dist/utils/postcssRpx2Vw.js +43 -33
  70. package/dist/utils/project.d.ts +3 -2
  71. package/dist/utils/project.js +129 -119
  72. package/dist/utils/projectConfig.js +24 -15
  73. package/dist/utils/utils.js +51 -42
  74. package/dist/utils/workerPool.d.ts +29 -0
  75. package/dist/utils/workerPool.js +125 -0
  76. package/dist/utils/zip.js +239 -229
  77. package/package.json +33 -14
  78. package/dist/compilerCP.d.ts +0 -1
  79. package/dist/compilerCP.js +0 -175
  80. package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
  81. package/dist/presets/loaders/sjs-loader/index.js +0 -605
  82. package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
  83. package/dist/presets/loaders/sjs-loader/scope.js +0 -122
  84. package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
  85. package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
  86. package/dist/utils/apm/index.js +0 -198
  87. package/dist/utils/asyncWebpack.d.ts +0 -3
  88. package/dist/utils/asyncWebpack.js +0 -38
  89. package/dist/utils/const.d.ts +0 -27
  90. package/dist/utils/const.js +0 -47
  91. package/dist/utils/getSuffixName.d.ts +0 -3
  92. package/dist/utils/getSuffixName.js +0 -18
  93. package/dist/utils/tagTransformMap.d.ts +0 -36
  94. package/dist/utils/tagTransformMap.js +0 -39
@@ -1,34 +1,53 @@
1
- "use strict";
2
1
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
2
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
3
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.presetService = void 0;
7
- const serviceEntryPlugin_1 = __importDefault(require("./serviceEntryPlugin"));
8
- const serviceChunkPlugin_1 = __importDefault(require("./serviceChunkPlugin"));
9
- const resolveLimitPlugin_1 = __importDefault(require("./resolveLimitPlugin"));
10
- const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
11
- const presetService = (chain, options) => {
12
- const { packSetting } = options;
13
- const { distDir } = packSetting;
14
- chain.merge({
15
- output: {
16
- path: distDir,
17
- globalObject: 'globalThis'
4
+ (function (factory) {
5
+ if (typeof module === "object" && typeof module.exports === "object") {
6
+ var v = factory(require, exports);
7
+ if (v !== undefined) module.exports = v;
8
+ }
9
+ else if (typeof define === "function" && define.amd) {
10
+ define(["require", "exports", "path", "./serviceEntryPlugin", "./serviceChunkPlugin", "./resolveLimitPlugin", "../../../plugins/InjectorPlugin", "../../../plugins/SourceMapDevToolPlugin", "../../../../utils/cache"], factory);
11
+ }
12
+ })(function (require, exports) {
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.presetService = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const serviceEntryPlugin_1 = __importDefault(require("./serviceEntryPlugin"));
18
+ const serviceChunkPlugin_1 = __importDefault(require("./serviceChunkPlugin"));
19
+ const resolveLimitPlugin_1 = __importDefault(require("./resolveLimitPlugin"));
20
+ const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
21
+ const SourceMapDevToolPlugin_1 = require("../../../plugins/SourceMapDevToolPlugin");
22
+ const cache_1 = require("../../../../utils/cache");
23
+ const presetService = (chain, options) => {
24
+ const { packSetting } = options;
25
+ const { distDir, cacheDirectory, enableSourcemap, appendSourcemapComment } = packSetting;
26
+ const absCacheDirectory = path_1.default.join(cacheDirectory, 'service');
27
+ chain.merge(Object.assign(Object.assign({}, (0, cache_1.getCacheConfig)(absCacheDirectory, options)), { output: {
28
+ path: distDir,
29
+ globalObject: 'globalThis'
30
+ } }));
31
+ chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
32
+ chain.plugin('ServiceEntryPlugin').use(serviceEntryPlugin_1.default, [options]);
33
+ chain.plugin('ServiceChunkPlugin').use(serviceChunkPlugin_1.default, [options]);
34
+ if (enableSourcemap && !appendSourcemapComment) {
35
+ const SourceMapDevToolPlugin = (0, SourceMapDevToolPlugin_1.getSourceMapDevtoolPlugin)(options.packMode);
36
+ chain.plugin('SourceMapDevToolPlugin').use(SourceMapDevToolPlugin, [{
37
+ filename: '[file].map',
38
+ append: false
39
+ }]);
18
40
  }
19
- });
20
- chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
21
- chain.plugin('ServiceEntryPlugin').use(serviceEntryPlugin_1.default, [options]);
22
- chain.plugin('ServiceChunkPlugin').use(serviceChunkPlugin_1.default, [options]);
23
- chain.resolve.plugin('ResolveLimitPlugin').use(resolveLimitPlugin_1.default, [options]);
24
- chain.optimization
25
- .runtimeChunk({
26
- name: 'runtime'
27
- })
28
- .splitChunks({
29
- chunks: chunk => !chunk.name.startsWith('v0/'),
30
- minSize: 0,
31
- name: 'service-common'
32
- });
33
- };
34
- exports.presetService = presetService;
41
+ chain.resolve.plugin('ResolveLimitPlugin').use(resolveLimitPlugin_1.default, [options]);
42
+ chain.optimization
43
+ .runtimeChunk({
44
+ name: 'runtime'
45
+ })
46
+ .splitChunks({
47
+ chunks: chunk => !chunk.name.startsWith('v0/'),
48
+ minSize: 0,
49
+ name: 'service-common'
50
+ });
51
+ };
52
+ exports.presetService = presetService;
53
+ });
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,28 +7,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const fs_extra_1 = require("fs-extra");
13
- class XhsResolveLimitPlugin {
14
- constructor(options) {
15
- this.options = options;
10
+ (function (factory) {
11
+ if (typeof module === "object" && typeof module.exports === "object") {
12
+ var v = factory(require, exports);
13
+ if (v !== undefined) module.exports = v;
16
14
  }
17
- apply(resolver) {
18
- const target1 = resolver.ensureHook("resolve");
19
- resolver.getHook('file')
20
- .tapAsync('XhsResolveLimitPlugin', (request, contextResolver, callback) => __awaiter(this, void 0, void 0, function* () {
21
- var _a;
22
- // @ts-ignore
23
- const issuer = ((_a = request.context) === null || _a === void 0 ? void 0 : _a.issuer) || '';
24
- const target = request.path || '';
25
- if ((target.includes('node_modules') && (0, fs_extra_1.existsSync)(target))) {
15
+ else if (typeof define === "function" && define.amd) {
16
+ define(["require", "exports", "fs-extra"], factory);
17
+ }
18
+ })(function (require, exports) {
19
+ "use strict";
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ const fs_extra_1 = require("fs-extra");
22
+ class XhsResolveLimitPlugin {
23
+ constructor(options) {
24
+ this.options = options;
25
+ }
26
+ apply(resolver) {
27
+ const target1 = resolver.ensureHook("resolve");
28
+ resolver.getHook('file')
29
+ .tapAsync('XhsResolveLimitPlugin', (request, contextResolver, callback) => __awaiter(this, void 0, void 0, function* () {
30
+ var _a;
31
+ // @ts-ignore
32
+ const issuer = ((_a = request.context) === null || _a === void 0 ? void 0 : _a.issuer) || '';
33
+ const target = request.path || '';
34
+ if ((target.includes('node_modules') && (0, fs_extra_1.existsSync)(target))) {
35
+ return callback();
36
+ }
37
+ // console.log(`issuer: ${issuer}`, `target: ${target}`)
38
+ // return resolver.doResolve(target1, request, null, contextResolver, callback);
39
+ // console.log(issuer, target)
26
40
  return callback();
27
- }
28
- // console.log(`issuer: ${issuer}`, `target: ${target}`)
29
- // return resolver.doResolve(target1, request, null, contextResolver, callback);
30
- // console.log(issuer, target)
31
- return callback();
32
- }));
41
+ }));
42
+ }
33
43
  }
34
- }
35
- exports.default = XhsResolveLimitPlugin;
44
+ exports.default = XhsResolveLimitPlugin;
45
+ });
@@ -1,9 +1,9 @@
1
- import { Compiler } from 'webpack';
1
+ import { ICompiler } from '../../../../packs';
2
2
  import { IPresetOptions } from '../../../../types';
3
3
  declare class ServiceChunkPlugin {
4
4
  options: IPresetOptions;
5
5
  constructor(options: IPresetOptions);
6
- apply(compiler: Compiler): void;
6
+ apply(compiler: ICompiler): void;
7
7
  updateService(compiler: any, compilation: any, runtimeCode: any, commonSource: any): void;
8
8
  }
9
9
  export default ServiceChunkPlugin;
@@ -1,69 +1,78 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const webpack_1 = require("webpack");
4
- const webpack_sources_1 = require("webpack-sources");
5
- const common_1 = require("../../../../utils/common");
6
- class ServiceChunkPlugin {
7
- constructor(options) {
8
- this.options = options;
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
9
5
  }
10
- apply(compiler) {
11
- compiler.hooks.compilation.tap('ServiceChunkPlugin', compilation => {
12
- compilation.hooks.processAssets.tap({
13
- name: 'ServiceChunkPlugin',
14
- stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
15
- }, () => {
16
- var _a, _b;
17
- let runtimeCode = (_a = compilation.getAsset('runtime.js')) === null || _a === void 0 ? void 0 : _a.source.source();
18
- // 当没有引用相同 js 场景时, commonChunk 将是 undefined
19
- const commonSource = ((_b = compilation.getAsset('service-common.js')) === null || _b === void 0 ? void 0 : _b.source) || '';
20
- runtimeCode = `
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../../../../packs", "../../../../packs", "../../../../utils/common"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const packs_1 = require("../../../../packs");
13
+ const packs_2 = require("../../../../packs");
14
+ const common_1 = require("../../../../utils/common");
15
+ class ServiceChunkPlugin {
16
+ constructor(options) {
17
+ this.options = options;
18
+ }
19
+ apply(compiler) {
20
+ compiler.hooks.compilation.tap('ServiceChunkPlugin', compilation => {
21
+ compilation.hooks.processAssets.tap({
22
+ name: 'ServiceChunkPlugin',
23
+ stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
24
+ }, () => {
25
+ var _a, _b;
26
+ let runtimeCode = (_a = compilation.getAsset('runtime.js')) === null || _a === void 0 ? void 0 : _a.source.source();
27
+ // 当没有引用相同 js 场景时, commonChunk 将是 undefined
28
+ const commonSource = ((_b = compilation.getAsset('service-common.js')) === null || _b === void 0 ? void 0 : _b.source) || '';
29
+ runtimeCode = `
21
30
  if (!globalThis.__XHS_RUNTIME_REGISTERED__) {
22
31
  globalThis.__XHS_RUNTIME_REGISTERED__ = true;
23
32
  ${runtimeCode}
24
33
  }`;
25
- this.updateService(compiler, compilation, runtimeCode, commonSource);
26
- compilation.deleteAsset('runtime.js');
27
- compilation.deleteAsset('service-common.js');
28
- });
29
- compilation.hooks.processAssets.tap({
30
- name: 'ServiceChunkPlugin1',
31
- stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
32
- }, (assets) => {
33
- var _a;
34
- const { project } = this.options;
35
- // service层注入gameGlobal
36
- const services = [
37
- "v1/service.js",
38
- // @ts-ignore
39
- ...(_a = project.appJSON.subPackages) === null || _a === void 0 ? void 0 : _a.map(i => (0, common_1.unixJoin)('v1', `${i.entry}.js`))
40
- ];
41
- services.forEach(servicePath => {
42
- if (servicePath in assets) {
43
- // @ts-ignore
44
- compilation.updateAsset(servicePath, new webpack_sources_1.ConcatSource(`with(GameGlobal) {\n"use strict";\n`, assets[servicePath], '\n}'));
45
- }
34
+ this.updateService(compiler, compilation, runtimeCode, commonSource);
35
+ compilation.deleteAsset('runtime.js');
36
+ compilation.deleteAsset('service-common.js');
37
+ });
38
+ compilation.hooks.processAssets.tap({
39
+ name: 'ServiceChunkPlugin1',
40
+ stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
41
+ }, (assets) => {
42
+ var _a;
43
+ const { project } = this.options;
44
+ // service层注入gameGlobal
45
+ const services = [
46
+ "v1/service.js",
47
+ // @ts-ignore
48
+ ...(_a = project.appJSON.subPackages) === null || _a === void 0 ? void 0 : _a.map(i => (0, common_1.unixJoin)('v1', `${i.entry}.js`))
49
+ ];
50
+ services.forEach(servicePath => {
51
+ if (servicePath in assets) {
52
+ // @ts-ignore
53
+ compilation.updateAsset(servicePath, new packs_2.ConcatSource(`with(GameGlobal) {\n"use strict";\n`, assets[servicePath], '\n}'));
54
+ }
55
+ });
46
56
  });
47
57
  });
48
- });
49
- }
50
- updateService(compiler, compilation, runtimeCode, commonSource) {
51
- var _a;
52
- const { project } = this.options;
53
- // 独立分包
54
- const independent = (_a = project.appJSON.subPackages) === null || _a === void 0 ? void 0 : _a.filter(sub => sub.independent);
55
- const services = [
56
- "v1/service.js",
57
- ...independent === null || independent === void 0 ? void 0 : independent.map(i => (0, common_1.unixJoin)('v1', `${i.entry}.js`))
58
- ];
59
- services.forEach(servicePath => {
58
+ }
59
+ updateService(compiler, compilation, runtimeCode, commonSource) {
60
60
  var _a;
61
- const serviceCode = (_a = compilation.getAsset(servicePath)) === null || _a === void 0 ? void 0 : _a.source;
62
- if (serviceCode) {
63
- // @ts-ignore
64
- compilation.updateAsset(servicePath, new webpack_sources_1.ConcatSource(runtimeCode, commonSource, serviceCode));
65
- }
66
- });
61
+ const { project } = this.options;
62
+ // 独立分包
63
+ const independent = (_a = project.appJSON.subPackages) === null || _a === void 0 ? void 0 : _a.filter(sub => sub.independent);
64
+ const services = [
65
+ "v1/service.js",
66
+ ...independent === null || independent === void 0 ? void 0 : independent.map(i => (0, common_1.unixJoin)('v1', `${i.entry}.js`))
67
+ ];
68
+ services.forEach(servicePath => {
69
+ var _a;
70
+ const serviceCode = (_a = compilation.getAsset(servicePath)) === null || _a === void 0 ? void 0 : _a.source;
71
+ if (serviceCode) {
72
+ compilation.updateAsset(servicePath, new packs_2.ConcatSource(runtimeCode, commonSource, serviceCode));
73
+ }
74
+ });
75
+ }
67
76
  }
68
- }
69
- exports.default = ServiceChunkPlugin;
77
+ exports.default = ServiceChunkPlugin;
78
+ });
@@ -1,10 +1,10 @@
1
- import { Compiler } from 'webpack';
1
+ import { ICompiler } from '../../../../packs';
2
2
  import { IPresetOptions } from '../../../../types';
3
3
  declare class ServiceEntryPlugin {
4
4
  entriesCache: Map<string, boolean>;
5
5
  options: IPresetOptions;
6
6
  constructor(options: IPresetOptions);
7
- apply(compiler: Compiler): void;
8
- makeUmdEntry(compiler: Compiler, filename: string, url: string, libraryName: string): void;
7
+ apply(compiler: ICompiler): void;
8
+ makeUmdEntry(compiler: ICompiler, filename: string, url: string, libraryName: string): void;
9
9
  }
10
10
  export default ServiceEntryPlugin;
@@ -1,32 +1,42 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const webpack_1 = require("webpack");
4
- const common_1 = require("../../../../utils/common");
5
- class ServiceEntryPlugin {
6
- constructor(options) {
7
- this.options = options;
8
- this.entriesCache = new Map();
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
9
5
  }
10
- apply(compiler) {
11
- new webpack_1.library.EnableLibraryPlugin('umd').apply(compiler);
12
- const { project } = this.options;
13
- const { appJSON } = project;
14
- const subPackages = appJSON.subPackages || [];
15
- this.makeUmdEntry(compiler, 'v1/service.js', `mg-entry-loader?entry=${common_1.DEFAULT_ENTRY}!`, `XHS_SERVICE_${common_1.DEFAULT_ENTRY}`);
16
- for (const { entry } of subPackages) {
17
- this.makeUmdEntry(compiler, (0, common_1.unixJoin)('v1', `${entry}.js`), `mg-entry-loader?entry=${entry}!`, `XHS_SERVICE_${entry}`);
18
- }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../../../../packs", "../../../../utils/common"], factory);
19
8
  }
20
- makeUmdEntry(compiler, filename, url, libraryName) {
21
- if (this.entriesCache.get(filename))
22
- return;
23
- const entryOption = webpack_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, filename, {
24
- import: [url],
25
- filename,
26
- library: { name: libraryName, type: 'umd' }
27
- });
28
- new webpack_1.EntryPlugin(compiler.context, url, entryOption).apply(compiler);
29
- this.entriesCache.set(filename, true);
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const packs_1 = require("../../../../packs");
13
+ const common_1 = require("../../../../utils/common");
14
+ class ServiceEntryPlugin {
15
+ constructor(options) {
16
+ this.options = options;
17
+ this.entriesCache = new Map();
18
+ }
19
+ apply(compiler) {
20
+ new packs_1.library.EnableLibraryPlugin('umd').apply(compiler);
21
+ const { project } = this.options;
22
+ const { appJSON } = project;
23
+ const subPackages = appJSON.subPackages || [];
24
+ this.makeUmdEntry(compiler, 'v1/service.js', `mg-entry-loader?entry=${common_1.DEFAULT_ENTRY}!`, `XHS_SERVICE_${common_1.DEFAULT_ENTRY}`);
25
+ for (const { entry } of subPackages) {
26
+ this.makeUmdEntry(compiler, (0, common_1.unixJoin)('v1', `${entry}.js`), `mg-entry-loader?entry=${entry}!`, `XHS_SERVICE_${entry}`);
27
+ }
28
+ }
29
+ makeUmdEntry(compiler, filename, url, libraryName) {
30
+ if (this.entriesCache.get(filename))
31
+ return;
32
+ const entryOption = packs_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, filename, {
33
+ import: [url],
34
+ filename,
35
+ library: { name: libraryName, type: 'umd' }
36
+ });
37
+ new packs_1.EntryPlugin(compiler.context, url, entryOption).apply(compiler);
38
+ this.entriesCache.set(filename, true);
39
+ }
30
40
  }
31
- }
32
- exports.default = ServiceEntryPlugin;
41
+ exports.default = ServiceEntryPlugin;
42
+ });