@umijs/plugins 4.0.7 → 4.0.10

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.
@@ -1,137 +1,179 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isMasterEnable = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const plugin_utils_1 = require("umi/plugin-utils");
7
- const withTmpPath_1 = require("../utils/withTmpPath");
8
- const constants_1 = require("./constants");
9
- function isMasterEnable(opts) {
10
- var _a;
11
- const masterCfg = (_a = opts.userConfig.qiankun) === null || _a === void 0 ? void 0 : _a.master;
12
- if (masterCfg) {
13
- return masterCfg.enable !== false;
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
14
20
  }
15
- return !!process.env.INITIAL_QIANKUN_MASTER_OPTIONS;
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+
39
+ // src/qiankun/master.ts
40
+ var master_exports = {};
41
+ __export(master_exports, {
42
+ default: () => master_default,
43
+ isMasterEnable: () => isMasterEnable
44
+ });
45
+ module.exports = __toCommonJS(master_exports);
46
+ var import_fs = require("fs");
47
+ var import_path = require("path");
48
+ var import_umi = require("umi");
49
+ var import_plugin_utils = require("umi/plugin-utils");
50
+ var import_withTmpPath = require("../utils/withTmpPath");
51
+ var import_constants = require("./constants");
52
+ function isMasterEnable(opts) {
53
+ var _a;
54
+ const masterCfg = (_a = opts.userConfig.qiankun) == null ? void 0 : _a.master;
55
+ if (masterCfg) {
56
+ return masterCfg.enable !== false;
57
+ }
58
+ return !!process.env.INITIAL_QIANKUN_MASTER_OPTIONS;
16
59
  }
17
- exports.isMasterEnable = isMasterEnable;
18
- exports.default = (api) => {
19
- api.describe({
20
- key: 'qiankun-master',
21
- enableBy: isMasterEnable,
22
- });
23
- api.addRuntimePlugin(() => {
24
- return [(0, withTmpPath_1.withTmpPath)({ api, path: 'masterRuntimePlugin.tsx' })];
25
- });
26
- api.modifyDefaultConfig((config) => ({
27
- ...config,
28
- mountElementId: constants_1.defaultMasterRootId,
29
- qiankun: {
30
- ...config.qiankun,
31
- master: {
32
- ...JSON.parse(process.env.INITIAL_QIANKUN_MASTER_OPTIONS || '{}'),
33
- ...(config.qiankun || {}).master,
34
- },
35
- },
36
- }));
37
- api.modifyRoutes((memo) => {
38
- Object.keys(memo).forEach((id) => {
39
- var _a;
40
- const route = memo[id];
41
- if (route.microApp) {
42
- const appName = route.microApp;
43
- const base = api.config.base || '/';
44
- const masterHistoryType = ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || 'browser';
45
- const routeProps = route.microAppProps || {};
46
- const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
47
- route.file = `(async () => {
60
+ var master_default = (api) => {
61
+ api.describe({
62
+ key: "qiankun-master",
63
+ enableBy: isMasterEnable
64
+ });
65
+ api.addRuntimePlugin(() => {
66
+ return [(0, import_withTmpPath.withTmpPath)({ api, path: "masterRuntimePlugin.tsx" })];
67
+ });
68
+ api.modifyDefaultConfig((config) => __spreadProps(__spreadValues({}, config), {
69
+ mountElementId: import_constants.defaultMasterRootId,
70
+ qiankun: __spreadProps(__spreadValues({}, config.qiankun), {
71
+ master: __spreadValues(__spreadValues({}, JSON.parse(process.env.INITIAL_QIANKUN_MASTER_OPTIONS || "{}")), (config.qiankun || {}).master)
72
+ })
73
+ }));
74
+ api.modifyRoutes((memo) => {
75
+ Object.keys(memo).forEach((id) => {
76
+ var _a;
77
+ const route = memo[id];
78
+ if (route.microApp) {
79
+ const appName = route.microApp;
80
+ const base = api.config.base || "/";
81
+ const masterHistoryType = ((_a = api.config.history) == null ? void 0 : _a.type) || "browser";
82
+ const routeProps = route.microAppProps || {};
83
+ const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
84
+ route.file = `(async () => {
48
85
  const { getMicroAppRouteComponent } = await import('@@/plugin-qiankun-master/getMicroAppRouteComponent');
49
86
  return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', routePath: '${route.path}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
50
87
  })()`;
51
- }
52
- });
53
- return memo;
88
+ }
54
89
  });
55
- // state model for slave app
56
- api.addRuntimePluginKey(() => [constants_1.MODEL_EXPORT_NAME]);
57
- api.register({
58
- key: 'addExtraModels',
59
- fn() {
60
- const { path, exports } = api.appData.appJS || {};
61
- return path && exports.includes(constants_1.MODEL_EXPORT_NAME)
62
- ? [
63
- `${path}#{"namespace":"${constants_1.qiankunStateForSlaveModelNamespace}","exportName":"${constants_1.MODEL_EXPORT_NAME}"}`,
64
- ]
65
- : [];
66
- },
67
- });
68
- function getFileContent(file) {
69
- return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/master', file), 'utf-8');
90
+ return memo;
91
+ });
92
+ api.addRuntimePluginKey(() => [import_constants.MODEL_EXPORT_NAME]);
93
+ api.register({
94
+ key: "addExtraModels",
95
+ fn() {
96
+ const { path, exports } = api.appData.appJS || {};
97
+ return path && exports.includes(import_constants.MODEL_EXPORT_NAME) ? [
98
+ `${path}#{"namespace":"${import_constants.qiankunStateForSlaveModelNamespace}","exportName":"${import_constants.MODEL_EXPORT_NAME}"}`
99
+ ] : [];
70
100
  }
71
- api.onGenerateFiles(() => {
72
- var _a;
73
- api.writeTmpFile({
74
- path: 'masterOptions.ts',
75
- content: `
76
- let options = ${JSON.stringify({
77
- masterHistoryType: ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || constants_1.defaultHistoryType,
78
- base: api.config.base || '/',
79
- ...api.config.qiankun.master,
80
- })};
101
+ });
102
+ function getFileContent(file) {
103
+ return (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../../libs/qiankun/master", file), "utf-8");
104
+ }
105
+ api.onGenerateFiles(() => {
106
+ var _a;
107
+ api.writeTmpFile({
108
+ path: import_umi.RUNTIME_TYPE_FILE_NAME,
109
+ content: `
110
+ import { MasterOptions } from './types'
111
+ type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
112
+ type XOR<T, U> = (Without<T, U> & U) | (Without<U, T> & T);
113
+ interface Config {
114
+ master?: MasterOptions;
115
+ }
116
+ export interface IRuntimeConfig {
117
+ qiankun?: XOR<MasterOptions, Config>;
118
+ ${import_constants.MODEL_EXPORT_NAME}?: () => Record<string, any>;
119
+ }
120
+ `
121
+ });
122
+ api.writeTmpFile({
123
+ path: "masterOptions.ts",
124
+ content: `
125
+ let options = ${JSON.stringify(__spreadValues({
126
+ masterHistoryType: ((_a = api.config.history) == null ? void 0 : _a.type) || import_constants.defaultHistoryType,
127
+ base: api.config.base || "/"
128
+ }, api.config.qiankun.master))};
81
129
  export const getMasterOptions = () => options;
82
130
  export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts });
83
- `,
84
- });
131
+ `
132
+ });
133
+ api.writeTmpFile({
134
+ path: "MicroAppLoader.tsx",
135
+ content: api.isPluginEnable("antd") ? getFileContent("AntdLoader.tsx") : `export default function Loader() { console.warn(\`[plugins/qiankun]: Seems like you'r not using @umijs/plugin-antd, you need to provide a custom loader or set autoSetLoading false to shut down this warning!\`); return null; }`
136
+ });
137
+ [
138
+ "common.ts",
139
+ "constants.ts",
140
+ "types.ts",
141
+ "masterRuntimePlugin.tsx",
142
+ "getMicroAppRouteComponent.tsx.tpl",
143
+ "ErrorBoundary.tsx",
144
+ "MicroApp.tsx",
145
+ "MicroAppWithMemoHistory.tsx"
146
+ ].forEach((file) => {
147
+ if (file.endsWith(".tpl")) {
85
148
  api.writeTmpFile({
86
- path: 'MicroAppLoader.tsx',
87
- // 开启了 antd 插件的时候,使用 antd 的 loader 组件,否则提示用户必须设置一个自定义的 loader 组件
88
- content: api.isPluginEnable('antd')
89
- ? getFileContent('AntdLoader.tsx')
90
- : `export default function Loader() { console.warn(\`[plugins/qiankun]: Seems like you'r not using @umijs/plugin-antd, you need to provide a custom loader or set autoSetLoading false to shut down this warning!\`); return null; }`,
91
- });
92
- [
93
- 'common.ts',
94
- 'constants.ts',
95
- 'types.ts',
96
- 'masterRuntimePlugin.tsx',
97
- 'getMicroAppRouteComponent.tsx.tpl',
98
- 'ErrorBoundary.tsx',
99
- 'MicroApp.tsx',
100
- 'MicroAppWithMemoHistory.tsx',
101
- ].forEach((file) => {
102
- if (file.endsWith('.tpl')) {
103
- api.writeTmpFile({
104
- path: file.replace(/\.tpl$/, ''),
105
- tpl: getFileContent(file),
106
- context: {
107
- dynamicRoot: false,
108
- hasModelPlugin: api.isPluginEnable('model'),
109
- // dynamicRoot:
110
- // api.config.exportStatic && api.config.exportStatic.dynamicRoot,
111
- },
112
- });
113
- }
114
- else {
115
- let content = getFileContent(file);
116
- if (!api.config.qiankun.externalQiankun) {
117
- content = content.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`);
118
- }
119
- api.writeTmpFile({
120
- path: file.replace(/\.tpl$/, ''),
121
- content: content
122
- .replace('__USE_MODEL__', api.isPluginEnable('model')
123
- ? `import { useModel } from '@@/plugin-model'`
124
- : `const useModel = null;`)
125
- .replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
126
- });
127
- }
149
+ path: file.replace(/\.tpl$/, ""),
150
+ tpl: getFileContent(file),
151
+ context: {
152
+ dynamicRoot: false,
153
+ hasModelPlugin: api.isPluginEnable("model")
154
+ }
128
155
  });
156
+ } else {
157
+ let content = getFileContent(file);
158
+ if (!api.config.qiankun.externalQiankun) {
159
+ content = content.replace(/from 'qiankun'/g, `from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("qiankun/package")))}'`);
160
+ }
129
161
  api.writeTmpFile({
130
- path: 'index.ts',
131
- content: `
162
+ path: file.replace(/\.tpl$/, ""),
163
+ content: content.replace("__USE_MODEL__", api.isPluginEnable("model") ? `import { useModel } from '@@/plugin-model'` : `const useModel = null;`).replace(/from 'lodash\//g, `from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("lodash/package")))}/`)
164
+ });
165
+ }
166
+ });
167
+ api.writeTmpFile({
168
+ path: "index.ts",
169
+ content: `
132
170
  export { MicroApp } from './MicroApp';
133
171
  export { MicroAppWithMemoHistory } from './MicroAppWithMemoHistory';
134
- `,
135
- });
172
+ `
136
173
  });
174
+ });
137
175
  };
176
+ // Annotate the CommonJS export names for ESM import in node:
177
+ 0 && (module.exports = {
178
+ isMasterEnable
179
+ });
@@ -1,119 +1,165 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
4
35
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const assert_1 = __importDefault(require("assert"));
7
- const fs_1 = require("fs");
8
- const path_1 = require("path");
9
- const plugin_utils_1 = require("umi/plugin-utils");
10
- const withTmpPath_1 = require("../utils/withTmpPath");
11
- const constants_1 = require("./constants");
12
- // BREAK CHANGE: 需要手动配置 slave: {},不能留空
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+
39
+ // src/qiankun/slave.ts
40
+ var slave_exports = {};
41
+ __export(slave_exports, {
42
+ default: () => slave_default
43
+ });
44
+ module.exports = __toCommonJS(slave_exports);
45
+ var import_assert = __toESM(require("assert"));
46
+ var import_fs = require("fs");
47
+ var import_path = require("path");
48
+ var import_umi = require("umi");
49
+ var import_plugin_utils = require("umi/plugin-utils");
50
+ var import_withTmpPath = require("../utils/withTmpPath");
51
+ var import_constants = require("./constants");
13
52
  function isSlaveEnable(opts) {
14
- var _a, _b;
15
- const slaveCfg = (_b = (_a = opts.userConfig) === null || _a === void 0 ? void 0 : _a.qiankun) === null || _b === void 0 ? void 0 : _b.slave;
16
- if (slaveCfg) {
17
- return slaveCfg.enable !== false;
53
+ var _a, _b;
54
+ const slaveCfg = (_b = (_a = opts.userConfig) == null ? void 0 : _a.qiankun) == null ? void 0 : _b.slave;
55
+ if (slaveCfg) {
56
+ return slaveCfg.enable !== false;
57
+ }
58
+ return !!process.env.INITIAL_QIANKUN_SLAVE_OPTIONS;
59
+ }
60
+ var slave_default = (api) => {
61
+ api.describe({
62
+ key: "qiankun-slave",
63
+ enableBy: isSlaveEnable
64
+ });
65
+ api.addRuntimePlugin(() => {
66
+ return [(0, import_withTmpPath.withTmpPath)({ api, path: "slaveRuntimePlugin.ts" })];
67
+ });
68
+ api.register({
69
+ key: "addExtraModels",
70
+ fn() {
71
+ return [
72
+ (0, import_withTmpPath.withTmpPath)({
73
+ api,
74
+ path: `qiankunModel.ts#{"namespace":"${import_constants.qiankunStateFromMasterModelNamespace}"}`
75
+ })
76
+ ];
18
77
  }
19
- return !!process.env.INITIAL_QIANKUN_SLAVE_OPTIONS;
78
+ });
79
+ api.onGenerateFiles(() => {
80
+ api.writeTmpFile({
81
+ path: import_umi.RUNTIME_TYPE_FILE_NAME,
82
+ content: `
83
+ interface LifeCycles {
84
+ bootstrap?: (props?: any) => Promise<any>;
85
+ mount?: (props?: any) => Promise<any>;
86
+ unmount?: (props?: any) => Promise<any>;
87
+ update?: (props?: any) => Promise<any>;
20
88
  }
21
- exports.default = (api) => {
22
- api.describe({
23
- key: 'qiankun-slave',
24
- enableBy: isSlaveEnable,
25
- });
26
- api.addRuntimePlugin(() => {
27
- return [(0, withTmpPath_1.withTmpPath)({ api, path: 'slaveRuntimePlugin.ts' })];
28
- });
29
- api.register({
30
- key: 'addExtraModels',
31
- fn() {
32
- return [
33
- (0, withTmpPath_1.withTmpPath)({
34
- api,
35
- path: `qiankunModel.ts#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
36
- }),
37
- ];
38
- },
39
- });
40
- api.modifyDefaultConfig((memo) => {
41
- var _a, _b, _c, _d;
42
- const initialSlaveOptions = {
43
- devSourceMap: true,
44
- ...JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}'),
45
- ...(memo.qiankun || {}).slave,
46
- };
47
- const modifiedDefaultConfig = {
48
- ...memo,
49
- // 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
50
- runtimePublicPath: true,
51
- qiankun: {
52
- ...memo.qiankun,
53
- slave: initialSlaveOptions,
54
- },
55
- };
56
- const shouldNotModifyDefaultBase = (_c = (_b = (_a = api.userConfig.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyDefaultBase) !== null && _c !== void 0 ? _c : initialSlaveOptions.shouldNotModifyDefaultBase;
57
- const historyType = ((_d = api.userConfig.history) === null || _d === void 0 ? void 0 : _d.type) || 'browser';
58
- if (!shouldNotModifyDefaultBase && historyType !== 'hash') {
59
- // @ts-ignore
60
- modifiedDefaultConfig.base = `/${api.pkg.name}`;
61
- }
62
- return modifiedDefaultConfig;
63
- });
64
- api.modifyConfig((config) => {
65
- var _a, _b;
66
- // mfsu 场景默认给子应用增加 mfName 配置,从而避免冲突
67
- if (config.mfsu !== false) {
68
- config.mfsu = {
69
- ...config.mfsu,
70
- mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
71
- `mf_${(_b = api.pkg.name) === null || _b === void 0 ? void 0 : _b.replace(/^@/, '').replace(/\W/g, '_')}`,
72
- };
73
- }
74
- return config;
75
- });
76
- api.addHTMLHeadScripts(() => {
77
- var _a, _b;
78
- const dontModify = (_b = (_a = api.config.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyRuntimePublicPath;
79
- return dontModify
80
- ? []
81
- : [
82
- `window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || '/'}";`,
83
- ];
84
- });
85
- api.chainWebpack((config) => {
86
- (0, assert_1.default)(api.pkg.name, 'You should have name in package.json.');
87
- const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
88
- config.output
89
- .libraryTarget('umd')
90
- .library(shouldNotAddLibraryChunkName ? api.pkg.name : `${api.pkg.name}-[name]`);
91
- // TODO: SOCKET_SERVER
92
- // TODO: devSourceMap
93
- return config;
89
+ type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
90
+ type XOR<T, U> = (Without<T, U> & U) | (Without<U, T> & T);
91
+ interface SlaveOption extends LifeCycles {
92
+ enable?: boolean;
93
+ }
94
+ interface Config {
95
+ slave?: SlaveOption;
96
+ }
97
+ export interface IRuntimeConfig {
98
+ qiankun?: XOR<Config, LifeCycles>
99
+ }
100
+ `
94
101
  });
95
- // umi bundle 添加 entry 标记
96
- api.modifyHTML(($) => {
97
- $('script').each((_, el) => {
98
- var _a;
99
- const scriptEl = $(el);
100
- const umiEntry = /\/?umi(\.\w+)?\.js$/g;
101
- if (umiEntry.test((_a = scriptEl.attr('src')) !== null && _a !== void 0 ? _a : '')) {
102
- scriptEl.attr('entry', '');
103
- }
104
- });
105
- return $;
102
+ });
103
+ api.modifyDefaultConfig((memo) => {
104
+ var _a, _b, _c;
105
+ const initialSlaveOptions = __spreadValues(__spreadValues({
106
+ devSourceMap: true
107
+ }, JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || "{}")), (memo.qiankun || {}).slave);
108
+ const modifiedDefaultConfig = __spreadProps(__spreadValues({}, memo), {
109
+ runtimePublicPath: true,
110
+ qiankun: __spreadProps(__spreadValues({}, memo.qiankun), {
111
+ slave: initialSlaveOptions
112
+ })
106
113
  });
107
- api.addEntryImports(() => {
108
- return [
109
- {
110
- source: '@@/plugin-qiankun-slave/lifecycles',
111
- specifier: '{ genMount as qiankun_genMount, genBootstrap as qiankun_genBootstrap, genUnmount as qiankun_genUnmount, genUpdate as qiankun_genUpdate }',
112
- },
113
- ];
114
+ const shouldNotModifyDefaultBase = ((_b = (_a = api.userConfig.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.shouldNotModifyDefaultBase) ?? initialSlaveOptions.shouldNotModifyDefaultBase;
115
+ const historyType = ((_c = api.userConfig.history) == null ? void 0 : _c.type) || "browser";
116
+ if (!shouldNotModifyDefaultBase && historyType !== "hash") {
117
+ modifiedDefaultConfig.base = `/${api.pkg.name}`;
118
+ }
119
+ return modifiedDefaultConfig;
120
+ });
121
+ api.modifyConfig((config) => {
122
+ var _a, _b;
123
+ if (config.mfsu !== false) {
124
+ config.mfsu = __spreadProps(__spreadValues({}, config.mfsu), {
125
+ mfName: ((_a = config.mfsu) == null ? void 0 : _a.mfName) || `mf_${(_b = api.pkg.name) == null ? void 0 : _b.replace(/^@/, "").replace(/\W/g, "_")}`
126
+ });
127
+ }
128
+ return config;
129
+ });
130
+ api.addHTMLHeadScripts(() => {
131
+ var _a, _b;
132
+ const dontModify = (_b = (_a = api.config.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.shouldNotModifyRuntimePublicPath;
133
+ return dontModify ? [] : [
134
+ `window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || "/"}";`
135
+ ];
136
+ });
137
+ api.chainWebpack((config) => {
138
+ (0, import_assert.default)(api.pkg.name, "You should have name in package.json.");
139
+ const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
140
+ config.output.libraryTarget("umd").library(shouldNotAddLibraryChunkName ? api.pkg.name : `${api.pkg.name}-[name]`);
141
+ return config;
142
+ });
143
+ api.modifyHTML(($) => {
144
+ $("script").each((_, el) => {
145
+ const scriptEl = $(el);
146
+ const umiEntry = /\/?umi(\.\w+)?\.js$/g;
147
+ if (umiEntry.test(scriptEl.attr("src") ?? "")) {
148
+ scriptEl.attr("entry", "");
149
+ }
114
150
  });
115
- api.addEntryCode(() => [
116
- `
151
+ return $;
152
+ });
153
+ api.addEntryImports(() => {
154
+ return [
155
+ {
156
+ source: "@@/plugin-qiankun-slave/lifecycles",
157
+ specifier: "{ genMount as qiankun_genMount, genBootstrap as qiankun_genBootstrap, genUnmount as qiankun_genUnmount, genUpdate as qiankun_genUpdate }"
158
+ }
159
+ ];
160
+ });
161
+ api.addEntryCode(() => [
162
+ `
117
163
  export const bootstrap = qiankun_genBootstrap(render);
118
164
  export const mount = qiankun_genMount('${api.config.mountElementId}');
119
165
  export const unmount = qiankun_genUnmount('${api.config.mountElementId}');
@@ -121,44 +167,33 @@ export const update = qiankun_genUpdate();
121
167
  if (!window.__POWERED_BY_QIANKUN__) {
122
168
  bootstrap().then(mount);
123
169
  }
124
- `,
125
- ]);
126
- function getFileContent(file) {
127
- return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/slave', file), 'utf-8');
128
- }
129
- api.onGenerateFiles({
130
- fn() {
131
- // api.writeTmpFile({
132
- // path: 'slaveOptions.ts',
133
- // content: `
134
- // let options = ${JSON.stringify((api.config.qiankun || {}).slave || {})};
135
- // export const getSlaveOptions = () => options;
136
- // export const setSlaveOptions = (newOpts) => options = ({ ...options, ...newOpts });
137
- // `,
138
- // });
139
- [
140
- 'qiankunModel.ts',
141
- 'connectMaster.tsx',
142
- 'slaveRuntimePlugin.ts',
143
- 'lifecycles.ts',
144
- ].forEach((file) => {
145
- api.writeTmpFile({
146
- path: file.replace(/\.tpl$/, ''),
147
- content: getFileContent(file)
148
- .replace('__USE_MODEL__', api.isPluginEnable('model')
149
- ? `import { useModel } from '@@/plugin-model'`
150
- : `const useModel = null;`)
151
- .replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
152
- .replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
153
- });
154
- });
155
- api.writeTmpFile({
156
- path: 'index.ts',
157
- content: `
170
+ `
171
+ ]);
172
+ function getFileContent(file) {
173
+ return (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../../libs/qiankun/slave", file), "utf-8");
174
+ }
175
+ api.onGenerateFiles({
176
+ fn() {
177
+ [
178
+ "qiankunModel.ts",
179
+ "connectMaster.tsx",
180
+ "slaveRuntimePlugin.ts",
181
+ "lifecycles.ts"
182
+ ].forEach((file) => {
183
+ api.writeTmpFile({
184
+ path: file.replace(/\.tpl$/, ""),
185
+ content: getFileContent(file).replace("__USE_MODEL__", api.isPluginEnable("model") ? `import { useModel } from '@@/plugin-model'` : `const useModel = null;`).replace(/from 'qiankun'/g, `from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("qiankun/package")))}'`).replace(/from 'lodash\//g, `from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("lodash/package")))}/`)
186
+ });
187
+ });
188
+ api.writeTmpFile({
189
+ path: "index.ts",
190
+ content: `
158
191
  export { connectMaster } from './connectMaster';
159
- `,
160
- });
161
- },
162
- before: 'model',
163
- });
192
+ `
193
+ });
194
+ },
195
+ before: "model"
196
+ });
164
197
  };
198
+ // Annotate the CommonJS export names for ESM import in node:
199
+ 0 && (module.exports = {});