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.
- package/dist/bin/xhs-mp-cli-build.js +48 -34
- package/dist/bin/xhs-mp-cli-dev.js +44 -44
- package/dist/bin/xhs-mp-cli.js +22 -12
- package/dist/compiler.d.ts +21 -28
- package/dist/compiler.js +327 -327
- package/dist/compilerImpl.d.ts +19 -0
- package/dist/compilerImpl.js +173 -0
- package/dist/config/constant.config.d.ts +24 -0
- package/dist/config/constant.config.js +82 -30
- package/dist/config/dir.config.js +23 -13
- package/dist/index.d.ts +9 -9
- package/dist/index.js +454 -408
- package/dist/packs/index.d.ts +4 -4
- package/dist/packs/index.js +38 -30
- package/dist/packs/mp-pack/index.js +38 -30
- package/dist/packs/webpack/dev-server/index.js +61 -50
- package/dist/packs/webpack/dev-server/lib/ensurePort.js +33 -23
- package/dist/packs/webpack/dev-server/lib/openBrowser.js +28 -18
- package/dist/packs/webpack/index.d.ts +1 -1
- package/dist/packs/webpack/index.js +99 -90
- package/dist/packs/webpack/webpack.d.ts +2 -1
- package/dist/packs/webpack/webpack.js +81 -63
- package/dist/presets/babel.d.ts +0 -1
- package/dist/presets/babel.js +64 -58
- package/dist/presets/common.js +42 -45
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +50 -40
- package/dist/presets/configs/minigame/assets/index.js +62 -52
- package/dist/presets/configs/minigame/service/index.js +49 -30
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +33 -23
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +2 -2
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -60
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +3 -3
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +39 -29
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +120 -113
- package/dist/presets/configs/miniprogram/assets/index.js +45 -43
- package/dist/presets/configs/miniprogram/render/component.js +51 -41
- package/dist/presets/configs/miniprogram/render/index.d.ts +2 -3
- package/dist/presets/configs/miniprogram/render/index.js +85 -68
- package/dist/presets/configs/miniprogram/render/render.js +53 -43
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +84 -49
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +164 -126
- package/dist/presets/configs/miniprogram/service/index.js +82 -65
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +60 -50
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +93 -55
- package/dist/presets/index.js +100 -90
- package/dist/presets/loaders/mg-entry-loader.js +32 -22
- package/dist/presets/loaders/mini-style-loader.js +79 -55
- package/dist/presets/loaders/mp-entry-loader.js +149 -140
- package/dist/presets/loaders/wxss-loader.js +73 -63
- package/dist/presets/plugins/InjectorPlugin.js +23 -13
- package/dist/presets/plugins/SourceMapDevToolPlugin.d.ts +1 -0
- package/dist/presets/plugins/SourceMapDevToolPlugin.js +23 -0
- package/dist/presets/prod.js +88 -78
- package/dist/sharedFs.d.ts +2 -0
- package/dist/sharedFs.js +24 -0
- package/dist/types/index.d.ts +11 -37
- package/dist/types/index.js +23 -13
- package/dist/utils/{apm/index.d.ts → apm.d.ts} +5 -3
- package/dist/utils/apm.js +245 -0
- package/dist/utils/cache.d.ts +28 -0
- package/dist/utils/cache.js +49 -0
- package/dist/utils/common.js +42 -32
- package/dist/utils/css.d.ts +1 -1
- package/dist/utils/css.js +43 -35
- package/dist/utils/depenedHelper.js +95 -85
- package/dist/utils/file.js +39 -29
- package/dist/utils/loader-utils.js +63 -53
- package/dist/utils/postcssRpx2Vw.js +43 -33
- package/dist/utils/project.d.ts +3 -2
- package/dist/utils/project.js +129 -119
- package/dist/utils/projectConfig.js +24 -15
- package/dist/utils/utils.js +51 -42
- package/dist/utils/workerPool.d.ts +29 -0
- package/dist/utils/workerPool.js +125 -0
- package/dist/utils/zip.js +239 -229
- package/package.json +33 -14
- package/dist/compilerCP.d.ts +0 -1
- package/dist/compilerCP.js +0 -175
- package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
- package/dist/presets/loaders/sjs-loader/index.js +0 -605
- package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
- package/dist/presets/loaders/sjs-loader/scope.js +0 -122
- package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
- package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
- package/dist/utils/apm/index.js +0 -198
- package/dist/utils/asyncWebpack.d.ts +0 -3
- package/dist/utils/asyncWebpack.js +0 -38
- package/dist/utils/const.d.ts +0 -27
- package/dist/utils/const.js +0 -47
- package/dist/utils/getSuffixName.d.ts +0 -3
- package/dist/utils/getSuffixName.js +0 -18
- package/dist/utils/tagTransformMap.d.ts +0 -36
- 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
|
-
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
// return resolver.doResolve(target1, request, null, contextResolver, callback);
|
|
30
|
-
// console.log(issuer, target)
|
|
31
|
-
return callback();
|
|
32
|
-
}));
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
33
43
|
}
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
exports.default = XhsResolveLimitPlugin;
|
|
45
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
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:
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
77
|
+
exports.default = ServiceChunkPlugin;
|
|
78
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
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:
|
|
8
|
-
makeUmdEntry(compiler:
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
41
|
+
exports.default = ServiceEntryPlugin;
|
|
42
|
+
});
|