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,71 +1,88 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
|
|
10
|
-
const getServiceEntry = options => () => {
|
|
11
|
-
const entries = {};
|
|
12
|
-
const { packSetting } = options;
|
|
13
|
-
if (packSetting.enableV2) {
|
|
14
|
-
appendV2Entry(options, entries);
|
|
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;
|
|
15
8
|
}
|
|
16
|
-
if (
|
|
17
|
-
|
|
9
|
+
else if (typeof define === "function" && define.amd) {
|
|
10
|
+
define(["require", "exports", "path", "xhs-mp-pack", "./serviceChunkPlugin", "../../../plugins/InjectorPlugin", "../../../plugins/SourceMapDevToolPlugin", "../../../../utils/cache"], factory);
|
|
18
11
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
exports
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
12
|
+
})(function (require, exports) {
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.presetService = exports.getServiceEntry = void 0;
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const xhs_mp_pack_1 = require("xhs-mp-pack");
|
|
18
|
+
const serviceChunkPlugin_1 = __importDefault(require("./serviceChunkPlugin"));
|
|
19
|
+
const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
|
|
20
|
+
const SourceMapDevToolPlugin_1 = require("../../../plugins/SourceMapDevToolPlugin");
|
|
21
|
+
const cache_1 = require("../../../../utils/cache");
|
|
22
|
+
const getServiceEntry = options => () => {
|
|
23
|
+
const entries = {};
|
|
24
|
+
const { packSetting } = options;
|
|
25
|
+
if (packSetting.enableV2) {
|
|
26
|
+
appendV2Entry(options, entries);
|
|
27
|
+
}
|
|
28
|
+
if (packSetting.enableV1) {
|
|
29
|
+
appendV1Entry(options, entries);
|
|
30
|
+
}
|
|
31
|
+
return entries;
|
|
32
|
+
};
|
|
33
|
+
exports.getServiceEntry = getServiceEntry;
|
|
34
|
+
const appendV2Entry = (options, entries) => {
|
|
35
|
+
const { packSetting } = options;
|
|
36
|
+
const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
|
|
37
|
+
if (mainPkg) {
|
|
38
|
+
entries['v2/service'] = `mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`;
|
|
39
|
+
}
|
|
40
|
+
for (const { root } of subPkgs) {
|
|
41
|
+
entries[`v2/${root}/service`] = `mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const appendV1Entry = (options, entries) => {
|
|
45
|
+
const { packSetting } = options;
|
|
46
|
+
const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
|
|
47
|
+
if (mainPkg) {
|
|
48
|
+
entries['v1/service'] = `mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`;
|
|
49
|
+
}
|
|
50
|
+
for (const { root } of subPkgs) {
|
|
51
|
+
entries[`v1/${root}/service`] = `mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const presetService = (chain, options) => {
|
|
55
|
+
const { packSetting } = options;
|
|
56
|
+
const { env, distDir, cacheDirectory, enableSourcemap, appendSourcemapComment } = packSetting;
|
|
57
|
+
const absCacheDirectory = path_1.default.join(cacheDirectory, 'service');
|
|
58
|
+
chain.merge(Object.assign({
|
|
59
|
+
// target: 'webworker',
|
|
60
|
+
output: {
|
|
61
|
+
path: distDir,
|
|
62
|
+
globalObject: 'globalThis',
|
|
63
|
+
libraryTarget: 'umd',
|
|
64
|
+
uniqueName: 'MpService',
|
|
65
|
+
} }, (0, cache_1.getCacheConfig)(absCacheDirectory, options)));
|
|
66
|
+
chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
|
|
67
|
+
chain.plugin('ServiceChunkPlugin').use(serviceChunkPlugin_1.default, [options]);
|
|
68
|
+
if (enableSourcemap && !appendSourcemapComment) {
|
|
69
|
+
const SourceMapDevToolPlugin = (0, SourceMapDevToolPlugin_1.getSourceMapDevtoolPlugin)(options.packMode);
|
|
70
|
+
chain.plugin('SourceMapDevToolPlugin').use(SourceMapDevToolPlugin, [{
|
|
71
|
+
filename: '[file].map',
|
|
72
|
+
append: false
|
|
73
|
+
}]);
|
|
74
|
+
}
|
|
75
|
+
chain.optimization.runtimeChunk({
|
|
76
|
+
name: 'runtime'
|
|
68
77
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
// dev模式下开启懒编译,不能抽离common chunk
|
|
79
|
+
if (env !== xhs_mp_pack_1.ENV.development) {
|
|
80
|
+
chain.optimization.splitChunks({
|
|
81
|
+
chunks: chunk => !chunk.name.startsWith('v0/'),
|
|
82
|
+
minSize: 0,
|
|
83
|
+
name: 'service-common'
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
exports.presetService = presetService;
|
|
88
|
+
});
|
|
@@ -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,59 +7,70 @@ 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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (issuer.startsWith(issuerSubPkg) && target.startsWith(issuerSubPkg)) {
|
|
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(compiler, resolver) {
|
|
27
|
+
resolver
|
|
28
|
+
.getHook('file')
|
|
29
|
+
.tapAsync('XhsResolveLimitPlugin', (request, contextResolver, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
var _a;
|
|
31
|
+
const { project } = this.options;
|
|
32
|
+
const projectMiniprogramPath = project.projectMiniprogramPath;
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
let issuer = ((_a = request.context) === null || _a === void 0 ? void 0 : _a.issuer) || '';
|
|
35
|
+
let target = request.path || '';
|
|
36
|
+
if (!issuer ||
|
|
37
|
+
target.includes('node_modules') ||
|
|
38
|
+
!issuer.startsWith(projectMiniprogramPath) ||
|
|
39
|
+
!target.startsWith(projectMiniprogramPath)) {
|
|
43
40
|
return callback();
|
|
44
41
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
issuer = issuer.replace(`${projectMiniprogramPath}/`, '');
|
|
43
|
+
target = target.replace(new RegExp(projectMiniprogramPath, 'g'), '').replace(/^\/+/g, '');
|
|
44
|
+
const appJSON = yield (0, fs_extra_1.readJson)(`${projectMiniprogramPath}/app.json`);
|
|
45
|
+
appJSON.subPackages = appJSON.subPackages || appJSON.subpackages || [];
|
|
46
|
+
const subPkgs = appJSON.subPackages.map(pkg => pkg.root);
|
|
47
|
+
// 当 issuer 是分包
|
|
48
|
+
const issuerSubPkg = subPkgs.find(pkg => issuer.startsWith(pkg));
|
|
49
|
+
if (issuerSubPkg) {
|
|
50
|
+
// 允许 target 和 issuer 在同一个分包
|
|
51
|
+
if (issuer.startsWith(issuerSubPkg) && target.startsWith(issuerSubPkg)) {
|
|
52
|
+
return callback();
|
|
53
|
+
}
|
|
54
|
+
// issuer 是分包 target 是主包
|
|
55
|
+
if (appJSON.pages.some(page => target.startsWith(page))) {
|
|
56
|
+
// 当 issuer 是 **独立分包** 时,不能引用主包资源
|
|
57
|
+
if (appJSON.subPackages.find(subPkg => subPkg.root === issuerSubPkg).independent) {
|
|
58
|
+
return callback(new Error(`${issuer} 在独立分包内,独立分包不可引用主包 ${target} 资源`), request);
|
|
59
|
+
}
|
|
60
|
+
return callback();
|
|
61
|
+
}
|
|
62
|
+
// issuer 是分包,target 是分包
|
|
63
|
+
if (subPkgs.some(sub => target.startsWith(sub))) {
|
|
64
|
+
return callback(new Error(`${issuer} 不能引用 ${target},因为他们不在同一个分包`), request);
|
|
50
65
|
}
|
|
51
|
-
return callback();
|
|
52
66
|
}
|
|
53
|
-
// issuer
|
|
54
|
-
if (subPkgs.some(
|
|
55
|
-
return callback(new Error(`${issuer}
|
|
67
|
+
// issuer 是主包,此时 target 不能在分包
|
|
68
|
+
if (subPkgs.some(pkg => target.startsWith(pkg))) {
|
|
69
|
+
return callback(new Error(`${issuer} 在主包内,主包不可引用分包资源 ${target}`), request);
|
|
56
70
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return callback(new Error(`${issuer} 在主包内,主包不可引用分包资源 ${target}`), request);
|
|
61
|
-
}
|
|
62
|
-
return callback();
|
|
63
|
-
}));
|
|
71
|
+
return callback();
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
64
74
|
}
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
exports.default = XhsResolveLimitPlugin;
|
|
76
|
+
});
|
|
@@ -1,65 +1,103 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(options) {
|
|
10
|
-
this.options = options;
|
|
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;
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
else if (typeof define === "function" && define.amd) {
|
|
10
|
+
define(["require", "exports", "path", "xhs-mp-pack", "webpack-sources"], factory);
|
|
11
|
+
}
|
|
12
|
+
})(function (require, exports) {
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const xhs_mp_pack_1 = require("xhs-mp-pack");
|
|
17
|
+
const webpack_sources_1 = require("webpack-sources");
|
|
18
|
+
function adapteServiceCode(assetName, serviceSource, packSetting) {
|
|
19
|
+
let result;
|
|
20
|
+
if (packSetting.runInServiceSandbox) {
|
|
21
|
+
const { source, map } = serviceSource === null || serviceSource === void 0 ? void 0 : serviceSource.sourceAndMap();
|
|
22
|
+
const beforeContent = '(function(window,document){';
|
|
23
|
+
const afterContent = '\n})(undefined,undefined)';
|
|
24
|
+
const newSource = beforeContent + source + afterContent;
|
|
25
|
+
result = new webpack_sources_1.SourceMapSource(newSource, // 新的资源内容
|
|
26
|
+
assetName, // 资源文件名
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
map, // 旧的 source map
|
|
29
|
+
source // 旧的源代码
|
|
30
|
+
);
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
result = serviceSource;
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
class ServiceChunkPlugin {
|
|
39
|
+
constructor(options) {
|
|
40
|
+
this.options = options;
|
|
41
|
+
}
|
|
42
|
+
apply(compiler) {
|
|
43
|
+
compiler.hooks.compilation.tap('ServiceChunkPlugin', (compilation) => {
|
|
44
|
+
compilation.hooks.processAssets.tap({
|
|
45
|
+
name: 'ServiceChunkPlugin'
|
|
46
|
+
}, () => {
|
|
47
|
+
var _a, _b, _c, _d;
|
|
48
|
+
const { project, packSetting } = this.options;
|
|
49
|
+
let serviceSourceV2 = (_a = compilation.getAsset('v2/service.js')) === null || _a === void 0 ? void 0 : _a.source;
|
|
50
|
+
let serviceSource = (_b = compilation.getAsset('v1/service.js')) === null || _b === void 0 ? void 0 : _b.source;
|
|
51
|
+
let runtimeCode = (_c = compilation.getAsset('runtime.js')) === null || _c === void 0 ? void 0 : _c.source.source();
|
|
52
|
+
// 当没有引用相同 js 场景时, commonChunk 将是 undefined
|
|
53
|
+
const commonSource = ((_d = compilation.getAsset('service-common.js')) === null || _d === void 0 ? void 0 : _d.source) || '';
|
|
54
|
+
runtimeCode = `if (!globalThis.__XHS_RUNTIME_REGISTERED__) {
|
|
26
55
|
globalThis.__XHS_RUNTIME_REGISTERED__ = true;
|
|
27
56
|
${runtimeCode}
|
|
28
57
|
}`;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
58
|
+
if (packSetting.enableV2 && serviceSourceV2) {
|
|
59
|
+
// 注入 v2 service.js
|
|
60
|
+
// 主包加入 runtimeChunk、commonChunk
|
|
61
|
+
const assetName = 'v2/service.js';
|
|
62
|
+
serviceSourceV2 = adapteServiceCode(assetName, serviceSourceV2, packSetting);
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
compilation.updateAsset(assetName, new xhs_mp_pack_1.ConcatSource(runtimeCode, commonSource, serviceSourceV2));
|
|
65
|
+
}
|
|
66
|
+
// 独立分包加入 runtimeChunk
|
|
67
|
+
if (packSetting.enableV1 && serviceSource) {
|
|
68
|
+
// // 主包加入 runtimeChunk、commonChunk
|
|
69
|
+
const assetName = 'v1/service.js';
|
|
70
|
+
serviceSource = adapteServiceCode(assetName, serviceSource, packSetting);
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
compilation.updateAsset(assetName, new xhs_mp_pack_1.ConcatSource(runtimeCode, commonSource, serviceSource));
|
|
73
|
+
}
|
|
74
|
+
this.updateIndependentService(compilation, runtimeCode);
|
|
75
|
+
compilation.deleteAsset('runtime.js');
|
|
76
|
+
compilation.deleteAsset('service-common.js');
|
|
77
|
+
});
|
|
42
78
|
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
}
|
|
80
|
+
updateIndependentService(compilation, runtimeCode) {
|
|
81
|
+
const { project, packSetting } = this.options;
|
|
82
|
+
const usingPackageType = packSetting.usingPackageType;
|
|
83
|
+
const subPackages = project.getSubPackages();
|
|
84
|
+
subPackages
|
|
85
|
+
.filter(sub => sub.independent)
|
|
86
|
+
.map(sub => path_1.default.join(usingPackageType, sub.root, 'service.js'))
|
|
87
|
+
.forEach(servicePath => {
|
|
88
|
+
var _a;
|
|
89
|
+
if (compilation.getAsset(servicePath)) {
|
|
90
|
+
let independentServiceSource = (_a = compilation.getAsset(servicePath)) === null || _a === void 0 ? void 0 : _a.source;
|
|
91
|
+
independentServiceSource = adapteServiceCode(servicePath, independentServiceSource, packSetting);
|
|
92
|
+
const subServiceSource = new xhs_mp_pack_1.ConcatSource(runtimeCode, independentServiceSource);
|
|
93
|
+
// 写入
|
|
94
|
+
compilation.updateAsset(servicePath, subServiceSource);
|
|
95
|
+
if (packSetting.enableV2 && packSetting.enableV1) {
|
|
96
|
+
compilation.updateAsset(servicePath.replace(usingPackageType, 'v1'), subServiceSource);
|
|
97
|
+
}
|
|
60
98
|
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
63
101
|
}
|
|
64
|
-
|
|
65
|
-
|
|
102
|
+
exports.default = ServiceChunkPlugin;
|
|
103
|
+
});
|