UNPKG

@morjs/plugin-compiler-bytedance

Version:

mor complier plugin for bytedance miniprogram

41 lines 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BytedanceCompilerPlugin = void 0; const utils_1 = require("@morjs/utils"); const bytedanceAsyncSubpackagePlugin_1 = require("./bytedanceAsyncSubpackagePlugin"); const PLUGIN_EXT_PREFIX = 'ext://'; /** * 字节小程序编译插件 */ class BytedanceCompilerPlugin { constructor() { this.name = 'BytedanceCompilerPlugin'; } apply(runner) { // 不处理 ext:// 插件扩展的页面或组件 runner.hooks.shouldAddPageOrComponent.tap(this.name, function (pageOrComponent) { if (pageOrComponent.startsWith(PLUGIN_EXT_PREFIX)) return false; }); let wrapper; runner.hooks.webpackWrapper.tap(this.name, function (webpackWrapper) { wrapper = webpackWrapper; }); // 标记 ext:// 开头的文件为 externals // 来避免被 webpack 打包 runner.hooks.userConfigValidated.tap(this.name, function () { const externals = (0, utils_1.asArray)(wrapper.chain.get('externals')); // 添加 externals 支持 externals.push(function ({ request }, callback) { if (request && request.startsWith(PLUGIN_EXT_PREFIX)) { return callback(null, `commonjs ${request}`); } callback(); }); wrapper.chain.externals(externals); }); new bytedanceAsyncSubpackagePlugin_1.BytedanceAsyncSubpackagePlugin().apply(runner); } } exports.BytedanceCompilerPlugin = BytedanceCompilerPlugin; //# sourceMappingURL=plugin.js.map