@morjs/plugin-compiler-bytedance
Version:
mor complier plugin for bytedance miniprogram
48 lines • 2.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BytedanceAsyncSubpackagePlugin = void 0;
const utils_1 = require("@morjs/utils");
const constants_1 = require("./constants");
/**
* 抖音支持异步分包插件
*/
class BytedanceAsyncSubpackagePlugin {
constructor() {
this.name = 'BytedanceAsyncSubpackagePlugin';
}
apply(runner) {
this.runner = runner;
this.runAsyncSubpackage();
}
runAsyncSubpackage() {
const runner = this.runner;
runner.hooks.userConfigValidated.tap(this.name, (userConfig) => {
const { target: compileTarget, compileType } = userConfig;
if (compileTarget === constants_1.target &&
(compileType === utils_1.CompileTypes.miniprogram ||
compileType === utils_1.CompileTypes.subpackage)) {
runner.hooks.beforeBuildEntries.tapPromise(this.name, async (entryBuilder) => {
var _a, _b, _c;
if (compileType === utils_1.CompileTypes.subpackage &&
((_a = entryBuilder === null || entryBuilder === void 0 ? void 0 : entryBuilder.subpackageJson) === null || _a === void 0 ? void 0 : _a.common) === true) {
// 分包项目场 且配置了 common: true 时执行
await entryBuilder.buildByGlob();
}
else if (compileType === utils_1.CompileTypes.miniprogram) {
// 小程序项目 部分分包配置了 common: true 时执行
const subpackagesArr = ((_b = entryBuilder === null || entryBuilder === void 0 ? void 0 : entryBuilder.appJson) === null || _b === void 0 ? void 0 : _b.subpackages) ||
((_c = entryBuilder === null || entryBuilder === void 0 ? void 0 : entryBuilder.appJson) === null || _c === void 0 ? void 0 : _c.subPackages) ||
[];
for await (const item of subpackagesArr) {
if (item.common === true && item.root) {
await entryBuilder.buildByGlob(`${item.root}/**`);
}
}
}
});
}
});
}
}
exports.BytedanceAsyncSubpackagePlugin = BytedanceAsyncSubpackagePlugin;
//# sourceMappingURL=bytedanceAsyncSubpackagePlugin.js.map