createIndependentPlugin.js 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
const AddShareAbilityToRuntimePlugin = require('./independent-plugins/add-share-ability-to-runtime-plugin');
const GenerateIndepndentEntryPlugin = require('./independent-plugins/generate-indepndent-entry-plugin');
const InjectEntryJsToIndependentPlugin = require('./independent-plugins/inject-entry-to-independent-plugin');
const InjectMainCssToIndependentCssPlugin = require('./independent-plugins/inject-main-css-to-independent-plugin');
const RunDefaultAppPlugin = require('./independent-plugins/run-default-app-plugin');
const SplitIndependentChunksPlugin = require('./independent-plugins/split-independent-chunks-plugin');
const ModifyUniAppWebpackConfigPlugin = require('./independent-plugins/modify-uniapp-webpack-config-Plugin');
const AddWxMpRuntimePlugin = require('./independent-plugins/add-weixin-mp-runtime-plugin');
const AppInterceptorPlugin = require('./independent-plugins/app-interceptor-plugin');

module.exports = function createIndependentPlugins () {
    const manifestConfig = process.UNI_MANIFEST;
    const weixinConfig = manifestConfig['mp-weixin'];
S
songyu 已提交
14
    const independentSwitch = !!weixinConfig.independent;
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
    if (!independentSwitch) return [];

    // 支持构造微信小程序的独立分包
    const independentPlugins = [
        new SplitIndependentChunksPlugin(),
        new ModifyUniAppWebpackConfigPlugin(), // 修改 webpack配置
        new AddShareAbilityToRuntimePlugin(), // 保证独立分包和主包使用的相同的runtime.js
        new GenerateIndepndentEntryPlugin(), // 生成独立分包执行入口文件(代替app.js
        new InjectEntryJsToIndependentPlugin(), // 为独立分包注入执行入口
        new RunDefaultAppPlugin(), // 确保app.js中的App()被执行一次
        // 独立分包中 App,getApp 调用拦截
        new AddWxMpRuntimePlugin(),
        new AppInterceptorPlugin()
    ];

S
songyu 已提交
30
    const insertAppCssToIndependentSwitch = !!weixinConfig.insertAppCssToIndependent;
31 32 33 34 35 36 37
    if (insertAppCssToIndependentSwitch) {
        // 需要在 cacheSet 后面
        independentPlugins.push(new InjectMainCssToIndependentCssPlugin()); // 目前只对页面注入了,组件未注入
    }

    return independentPlugins;
};