UNPKG

zephyr-rspress-plugin

Version:

Rspress plugin for Zephyr

106 lines (105 loc) • 4.47 kB
"use strict"; var __webpack_require__ = {}; (()=>{ __webpack_require__.d = (exports1, getters, values)=>{ var define = (defs, kind)=>{ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, { enumerable: true, [kind]: defs[key] }); }; define(getters, "get"); define(values, "value"); }; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports1)=>{ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports1, '__esModule', { value: true }); }; })(); var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { withZephyr: ()=>withZephyr }); const external_zephyr_rsbuild_plugin_namespaceObject = require("zephyr-rsbuild-plugin"); const external_zephyr_edge_contract_namespaceObject = require("zephyr-edge-contract"); const external_zephyrRspressSSGPlugin_js_namespaceObject = require("./zephyrRspressSSGPlugin.js"); const moduleFederationPublicPathPlugin_js_namespaceObject = require("./internal/assets/moduleFederationPublicPathPlugin.js"); function isRspressV1(config) { return 'builderPlugins' in config; } function isSsgEnabled(ssg) { return true === ssg || 'object' == typeof ssg && null !== ssg; } function withZephyr(options) { if (options?.target !== void 0) (0, external_zephyr_edge_contract_namespaceObject.assertZephyrBuildTarget)(options.target, 'withZephyr({ target })'); const mfConfigs = []; const portableFederationPlugin = (0, moduleFederationPublicPathPlugin_js_namespaceObject.moduleFederationPublicPathPlugin)({ target: options?.target, onModuleFederationPlugins (plugins) { mfConfigs.splice(0, mfConfigs.length, ...plugins); } }); return { name: 'zephyr-rspress-plugin', async config (config, { addPlugin }) { const { ssg } = config; if (isSsgEnabled(ssg)) { if (isRspressV1(config)) { const existingPlugins = config.builderPlugins ?? []; if (!existingPlugins.some((plugin)=>plugin === portableFederationPlugin)) config.builderPlugins = [ ...existingPlugins, portableFederationPlugin ]; } else { const existingPlugins = config.builderConfig?.plugins ?? []; const newBuilderConfig = { ...config.builderConfig, plugins: existingPlugins.some((plugin)=>plugin === portableFederationPlugin) ? existingPlugins : [ ...existingPlugins, portableFederationPlugin ] }; config.builderConfig = newBuilderConfig; } const ssgOptions = { ...options, mfConfig: mfConfigs }; addPlugin((0, external_zephyrRspressSSGPlugin_js_namespaceObject.zephyrRspressSSGPlugin)(config, ssgOptions)); } else if (isRspressV1(config)) config.builderPlugins = [ ...config.builderPlugins, (0, external_zephyr_rsbuild_plugin_namespaceObject.withZephyr)(options) ]; else { const existingPlugins = config.builderConfig?.plugins ?? []; const newBuilderConfig = { ...config.builderConfig, plugins: [ ...existingPlugins, (0, external_zephyr_rsbuild_plugin_namespaceObject.withZephyr)(options) ] }; config.builderConfig = newBuilderConfig; } return config; } }; } exports.withZephyr = __webpack_exports__.withZephyr; for(var __rspack_i in __webpack_exports__)if (-1 === [ "withZephyr" ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i]; Object.defineProperty(exports, '__esModule', { value: true }); //# sourceMappingURL=with-zephyr.js.map