@umijs/plugins 4.0.0-beta.13 → 4.0.0-beta.17

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.
Files changed (41) hide show
  1. package/README.md +4 -1
  2. package/dist/antd.js +2 -2
  3. package/dist/dva.js +4 -5
  4. package/dist/layout.js +47 -13
  5. package/dist/locale.d.ts +1 -0
  6. package/dist/locale.js +199 -1
  7. package/dist/qiankun/constants.d.ts +5 -0
  8. package/dist/qiankun/constants.js +8 -0
  9. package/dist/qiankun/master.d.ts +6 -0
  10. package/dist/qiankun/master.js +114 -0
  11. package/dist/qiankun/slave.d.ts +3 -0
  12. package/dist/qiankun/slave.js +141 -0
  13. package/dist/qiankun.js +15 -1
  14. package/dist/request.js +297 -1
  15. package/dist/tailwindcss.d.ts +3 -0
  16. package/dist/tailwindcss.js +38 -0
  17. package/dist/unocss.d.ts +3 -0
  18. package/dist/unocss.js +57 -0
  19. package/dist/utils/localeUtils.d.ts +33 -0
  20. package/dist/utils/localeUtils.js +135 -0
  21. package/dist/utils/modelUtils.d.ts +1 -0
  22. package/dist/utils/modelUtils.js +17 -3
  23. package/libs/locale/SelectLang.tpl +478 -0
  24. package/libs/locale/locale.tpl +82 -0
  25. package/libs/locale/localeExports.tpl +271 -0
  26. package/libs/locale/runtime.tpl +33 -0
  27. package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
  28. package/libs/qiankun/master/AntdLoader.tsx +15 -0
  29. package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
  30. package/libs/qiankun/master/MicroApp.tsx +262 -0
  31. package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
  32. package/libs/qiankun/master/common.ts +133 -0
  33. package/libs/qiankun/master/constants.ts +7 -0
  34. package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
  35. package/libs/qiankun/master/masterRuntimePlugin.tsx +130 -0
  36. package/libs/qiankun/master/types.ts +44 -0
  37. package/libs/qiankun/slave/connectMaster.tsx +15 -0
  38. package/libs/qiankun/slave/lifecycles.ts +149 -0
  39. package/libs/qiankun/slave/qiankunModel.ts +19 -0
  40. package/libs/qiankun/slave/slaveRuntimePlugin.ts +21 -0
  41. package/package.json +12 -4
package/README.md CHANGED
@@ -1,3 +1,6 @@
1
1
  # @umijs/plugins
2
2
 
3
- See our website [umijs](https://umijs.org) for more information.
3
+ See our website [umijs](https://umijs.org) for more information.
4
+
5
+
6
+
package/dist/antd.js CHANGED
@@ -52,7 +52,7 @@ exports.default = (api) => {
52
52
  // babel-plugin-import
53
53
  api.addExtraBabelPlugins(() => {
54
54
  const style = api.config.antd.style || 'less';
55
- return api.config.antd.import
55
+ return api.config.antd.import && !api.appData.vite
56
56
  ? [
57
57
  [
58
58
  require.resolve('babel-plugin-import'),
@@ -102,7 +102,7 @@ export function rootContainer(container) {
102
102
  // import antd style if antd.import is not configured
103
103
  api.addEntryImportsAhead(() => {
104
104
  const style = api.config.antd.style || 'less';
105
- return api.config.antd.import
105
+ return api.config.antd.import && !api.appData.vite
106
106
  ? []
107
107
  : [
108
108
  {
package/dist/dva.js CHANGED
@@ -47,7 +47,7 @@ exports.default = (api) => {
47
47
  });
48
48
  api.modifyConfig((memo) => {
49
49
  // import from dva
50
- memo.alias.dva = pkgPath;
50
+ memo.alias['dva$'] = pkgPath;
51
51
  return memo;
52
52
  });
53
53
  api.onGenerateFiles((args) => {
@@ -67,16 +67,15 @@ exports.default = (api) => {
67
67
  // aliased to @umijs/plugins/templates/dva
68
68
  import { create, Provider } from 'dva';
69
69
  import React, { useRef } from 'react';
70
- import { useAppData } from 'umi';
70
+ import { history } from 'umi';
71
71
  import { models } from './models';
72
72
 
73
73
  export function RootContainer(props: any) {
74
- const { navigator } = useAppData();
75
74
  const app = useRef<any>();
76
75
  if (!app.current) {
77
76
  app.current = create(
78
77
  {
79
- history: navigator,
78
+ history,
80
79
  },
81
80
  {
82
81
  initialReducer: {},
@@ -84,7 +83,7 @@ export function RootContainer(props: any) {
84
83
  return [...middlewares];
85
84
  },
86
85
  setupApp(app: IDvaApp) {
87
- app._history = navigator;
86
+ app._history = history;
88
87
  },
89
88
  },
90
89
  );
package/dist/layout.js CHANGED
@@ -74,6 +74,13 @@ ${hasInitialStatePlugin
74
74
  ? `import { useModel } from '@@/plugin-model';`
75
75
  : 'const useModel = null;'}
76
76
 
77
+ ${api.config.locale
78
+ ? `
79
+ import { useIntl } from '@@/plugin-locale';
80
+ `.trim()
81
+ : ''}
82
+
83
+
77
84
  export default () => {
78
85
  const location = useLocation();
79
86
  const navigate = useNavigate();
@@ -85,16 +92,26 @@ export default () => {
85
92
  };
86
93
  const { initialState, loading, setInitialState } = initialInfo;
87
94
  const userConfig = ${JSON.stringify(api.config.layout, null, 2)};
95
+ ${api.config.locale
96
+ ? `
97
+ const { formatMessage } = useIntl();
98
+ `.trim()
99
+ : 'const formatMessage = undefined;'}
88
100
  const runtimeConfig = pluginManager.applyPlugins({
89
101
  key: 'layout',
90
102
  type: 'modify',
91
- initialValue: {},
103
+ initialValue: {
104
+ ...initialInfo
105
+ },
92
106
  });
107
+ const route = clientRoutes.filter(r => {
108
+ return r.id === 'ant-design-pro-layout';
109
+ })[0];
93
110
  return (
94
111
  <ProLayout
95
- route={clientRoutes[0]}
112
+ route={route}
96
113
  location={location}
97
- title={userConfig.name || 'plugin-layout'}
114
+ title={userConfig.title || 'plugin-layout'}
98
115
  navTheme="dark"
99
116
  siderWidth={256}
100
117
  onMenuHeaderClick={(e) => {
@@ -102,6 +119,7 @@ export default () => {
102
119
  e.preventDefault();
103
120
  navigate('/');
104
121
  }}
122
+ formatMessage={userConfig.formatMessage || formatMessage}
105
123
  menu={{ locale: userConfig.locale }}
106
124
  logo={Logo}
107
125
  menuItemRender={(menuItemProps, defaultDom) => {
@@ -154,9 +172,13 @@ export default () => {
154
172
  const { icon } = api.appData.routes[id];
155
173
  if (icon) {
156
174
  const upperIcon = plugin_utils_1.lodash.upperFirst(plugin_utils_1.lodash.camelCase(icon));
175
+ (0, assert_1.default)(
176
+ // @ts-ignore
177
+ allIcons[upperIcon] || allIcons[`${upperIcon}Outlined`], `Icon ${upperIcon} is not found`);
157
178
  // @ts-ignore
158
- (0, assert_1.default)(allIcons[upperIcon], `Icon ${upperIcon} is not found`);
159
- memo[upperIcon] = true;
179
+ if (allIcons[upperIcon]) {
180
+ memo[upperIcon] = true;
181
+ }
160
182
  // @ts-ignore
161
183
  if (allIcons[`${upperIcon}Outlined`]) {
162
184
  memo[`${upperIcon}Outlined`] = true;
@@ -203,13 +225,13 @@ export function patchRoutes({ routes }) {
203
225
  }
204
226
  `,
205
227
  });
206
- // rightRender.tsx
207
- api.writeTmpFile({
208
- path: 'rightRender.tsx',
209
- content: `
228
+ const rightRenderContent = `
210
229
  import React from 'react';
211
230
  import { Avatar, Dropdown, Menu, Spin } from 'antd';
212
231
  import { LogoutOutlined } from '@ant-design/icons';
232
+ {{#Locale}}
233
+ import { SelectLang } from '@@/plugin-locale';
234
+ {{/Locale}}
213
235
 
214
236
  export function getRightRenderContent (opts: {
215
237
  runtimeConfig: any,
@@ -257,7 +279,7 @@ export function getRightRenderContent (opts: {
257
279
  if (opts.loading) {
258
280
  return (
259
281
  <div className="umi-plugin-layout-right">
260
- <Spin size="small" style={{ marginLeft: 8, marginRight: 8 }} />
282
+ <Spin size="small" style={ { marginLeft: 8, marginRight: 8 } } />
261
283
  </div>
262
284
  );
263
285
  }
@@ -271,11 +293,20 @@ export function getRightRenderContent (opts: {
271
293
  ) : (
272
294
  avatar
273
295
  )}
296
+ {{#Locale}}
297
+ <SelectLang />
298
+ {{/Locale}}
274
299
  </div>
275
300
  );
276
- // TODO: <SelectLang />
277
301
  }
278
- `,
302
+ `;
303
+ const Locale = api.isPluginEnable('locale');
304
+ // rightRender.tsx
305
+ api.writeTmpFile({
306
+ path: 'rightRender.tsx',
307
+ content: plugin_utils_1.Mustache.render(rightRenderContent, {
308
+ Locale,
309
+ }),
279
310
  });
280
311
  // Layout.less
281
312
  api.writeTmpFile({
@@ -301,7 +332,7 @@ export function getRightRenderContent (opts: {
301
332
  }
302
333
  }
303
334
  .umi-plugin-layout-right {
304
- display: flex;
335
+ display: flex !important;
305
336
  float: right;
306
337
  height: 100%;
307
338
  margin-left: auto;
@@ -439,6 +470,9 @@ export default LogoIcon;
439
470
  {
440
471
  id: 'ant-design-pro-layout',
441
472
  file: (0, withTmpPath_1.withTmpPath)({ api, path: 'Layout.tsx' }),
473
+ test: (route) => {
474
+ return route.layout !== false;
475
+ },
442
476
  },
443
477
  ];
444
478
  });
package/dist/locale.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { IApi } from 'umi';
2
+ export declare const packageNormalize: (packageName: string) => string;
2
3
  declare const _default: (api: IApi) => void;
3
4
  export default _default;
package/dist/locale.js CHANGED
@@ -1,5 +1,203 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.packageNormalize = void 0;
13
+ const utils_1 = require("@umijs/utils");
14
+ const fs_1 = require("fs");
15
+ const path_1 = require("path");
16
+ const localeUtils_1 = require("./utils/localeUtils");
17
+ const withTmpPath_1 = require("./utils/withTmpPath");
18
+ const packageNormalize = (packageName) => packageName.replace(/[@\/\-.]/g, '_');
19
+ exports.packageNormalize = packageNormalize;
20
+ // TODO: runtime plugin
3
21
  exports.default = (api) => {
4
- api;
22
+ var _a;
23
+ // TODO: antd 的校验考虑 antd 插件
24
+ let hasAntd = false;
25
+ try {
26
+ hasAntd = !!require.resolve('antd');
27
+ }
28
+ catch (e) {
29
+ api.logger.warn('antd is not installed. <SelecLang /> unavailable');
30
+ }
31
+ api.describe({
32
+ key: 'locale',
33
+ config: {
34
+ default: {
35
+ baseNavigator: true,
36
+ useLocalStorage: true,
37
+ baseSeparator: '-',
38
+ antd: hasAntd,
39
+ },
40
+ schema(joi) {
41
+ return joi.object({
42
+ default: joi.string(),
43
+ useLocalStorage: joi.boolean(),
44
+ baseNavigator: joi.boolean(),
45
+ title: joi.boolean(),
46
+ antd: joi.boolean(),
47
+ baseSeparator: joi.string(),
48
+ });
49
+ },
50
+ },
51
+ enableBy: api.EnableBy.config,
52
+ });
53
+ const reactIntlPkgPath = (0, path_1.dirname)(require.resolve('react-intl/package'));
54
+ // polyfill
55
+ if ((0, localeUtils_1.isNeedPolyfill)(((_a = api.userConfig) === null || _a === void 0 ? void 0 : _a.targets) || {})) {
56
+ api.addEntryImportsAhead(() => [
57
+ {
58
+ source: require.resolve('intl'),
59
+ },
60
+ ]);
61
+ }
62
+ const addAntdLocales = (args) => __awaiter(void 0, void 0, void 0, function* () {
63
+ var _b;
64
+ return yield api.applyPlugins({
65
+ key: 'addAntdLocales',
66
+ type: api.ApplyPluginsType.add,
67
+ initialValue: [
68
+ `antd/${((_b = api.config) === null || _b === void 0 ? void 0 : _b.ssr) ? 'lib' : 'es'}/locale/${(0, localeUtils_1.getAntdLocale)(args.lang, args.country)}`,
69
+ ],
70
+ args,
71
+ });
72
+ });
73
+ const getList = (resolveKey) => __awaiter(void 0, void 0, void 0, function* () {
74
+ var _c, _d;
75
+ const { paths } = api;
76
+ return (0, localeUtils_1.getLocaleList)({
77
+ localeFolder: ((_c = api.config) === null || _c === void 0 ? void 0 : _c.singular) ? 'locale' : 'locales',
78
+ separator: (_d = api.config.locale) === null || _d === void 0 ? void 0 : _d.baseSeparator,
79
+ absSrcPath: paths.absSrcPath,
80
+ absPagesPath: paths.absPagesPath,
81
+ addAntdLocales,
82
+ resolveKey,
83
+ });
84
+ });
85
+ api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
86
+ var _e, _f, _g, _h;
87
+ const localeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/locale.tpl'), 'utf-8');
88
+ // moment2dayjs
89
+ const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
90
+ const momentPkgPath = (0, path_1.dirname)(require.resolve(`${resolveKey}/package.json`));
91
+ const EventEmitterPkg = (0, path_1.dirname)(require.resolve('event-emitter/package'));
92
+ const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = api
93
+ .config.locale;
94
+ const defaultLocale = ((_e = api.config.locale) === null || _e === void 0 ? void 0 : _e.default) || `zh${baseSeparator}CN`;
95
+ const localeList = yield getList(resolveKey);
96
+ const momentLocales = localeList
97
+ .map(({ momentLocale }) => momentLocale)
98
+ .filter((locale) => locale);
99
+ const antdLocales = localeList
100
+ .map(({ antdLocale }) => antdLocale)
101
+ .filter((locale) => locale);
102
+ let MomentLocales = momentLocales;
103
+ let DefaultMomentLocale = '';
104
+ // set moment default accounding to locale.default
105
+ if (!MomentLocales.length && ((_f = api.config.locale) === null || _f === void 0 ? void 0 : _f.default)) {
106
+ const [lang, country = ''] = defaultLocale.split(baseSeparator);
107
+ const { momentLocale } = (0, localeUtils_1.getMomentLocale)(lang, country, resolveKey);
108
+ if (momentLocale) {
109
+ MomentLocales = [momentLocale];
110
+ DefaultMomentLocale = momentLocale;
111
+ }
112
+ }
113
+ let DefaultAntdLocales = [];
114
+ // set antd default locale
115
+ if (!antdLocales.length && ((_g = api.config.locale) === null || _g === void 0 ? void 0 : _g.antd)) {
116
+ const [lang, country = ''] = defaultLocale.split(baseSeparator);
117
+ DefaultAntdLocales = utils_1.lodash.uniq(yield addAntdLocales({
118
+ lang,
119
+ country,
120
+ }));
121
+ }
122
+ const NormalizeAntdLocalesName = function () {
123
+ // @ts-ignore
124
+ return (0, exports.packageNormalize)(this);
125
+ };
126
+ api.writeTmpFile({
127
+ content: utils_1.Mustache.render(localeTpl, {
128
+ MomentLocales,
129
+ DefaultMomentLocale,
130
+ NormalizeAntdLocalesName,
131
+ DefaultAntdLocales,
132
+ Antd: !!antd,
133
+ Title: title && api.config.title,
134
+ BaseSeparator: baseSeparator,
135
+ DefaultLocale: defaultLocale,
136
+ DefaultLang: defaultLocale,
137
+ momentPkgPath,
138
+ }),
139
+ path: 'locale.tsx',
140
+ });
141
+ const localeExportsTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/localeExports.tpl'), 'utf-8');
142
+ const localeDirName = api.config.singular ? 'locale' : 'locales';
143
+ const localeDirPath = (0, path_1.join)(api.paths.absSrcPath, localeDirName);
144
+ api.writeTmpFile({
145
+ path: 'localeExports.ts',
146
+ content: utils_1.Mustache.render(localeExportsTpl, {
147
+ EventEmitterPkg,
148
+ BaseSeparator: baseSeparator,
149
+ BaseNavigator: baseNavigator,
150
+ UseLocalStorage: !!useLocalStorage,
151
+ LocaleDir: localeDirName,
152
+ ExistLocaleDir: (0, fs_1.existsSync)(localeDirPath),
153
+ LocaleList: localeList.map((locale) => (Object.assign(Object.assign({}, locale), { antdLocale: locale.antdLocale.map((antdLocale, index) => ({
154
+ locale: antdLocale,
155
+ index: index,
156
+ })), paths: locale.paths.map((path, index) => ({
157
+ path,
158
+ index,
159
+ })) }))),
160
+ Antd: !!antd,
161
+ DefaultLocale: JSON.stringify(defaultLocale),
162
+ warningPkgPath: require.resolve('warning/package'),
163
+ reactIntlPkgPath,
164
+ }),
165
+ });
166
+ // runtime.tsx
167
+ const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/runtime.tpl'), 'utf-8');
168
+ api.writeTmpFile({
169
+ path: 'runtime.tsx',
170
+ content: utils_1.Mustache.render(runtimeTpl, {
171
+ Title: !!title,
172
+ }),
173
+ });
174
+ // SelectLang.tsx
175
+ const selectLang = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/SelectLang.tpl'), 'utf-8');
176
+ api.writeTmpFile({
177
+ path: 'SelectLang.tsx',
178
+ content: utils_1.Mustache.render(selectLang, {
179
+ Antd: !!antd,
180
+ LocaleList: localeList,
181
+ ShowSelectLang: localeList.length > 1 && !!antd,
182
+ antdFiles: ((_h = api.config) === null || _h === void 0 ? void 0 : _h.ssr) ? 'lib' : 'es',
183
+ }),
184
+ });
185
+ // index.ts
186
+ api.writeTmpFile({
187
+ path: 'index.ts',
188
+ content: `
189
+ export { useIntl, formatMessage, FormattedMessage } from './localeExports.ts';
190
+ export { SelectLang } from './SelectLang.tsx';
191
+ `,
192
+ });
193
+ }));
194
+ // Runtime Plugin
195
+ api.addRuntimePlugin(() => [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]);
196
+ api.addRuntimePluginKey(() => ['locale']);
197
+ // watch locale files
198
+ api.addTmpGenerateWatcherPaths(() => __awaiter(void 0, void 0, void 0, function* () {
199
+ const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
200
+ const localeList = yield getList(resolveKey);
201
+ return (0, localeUtils_1.exactLocalePaths)(localeList);
202
+ }));
5
203
  };
@@ -0,0 +1,5 @@
1
+ export declare const defaultMasterRootId = "root-master";
2
+ export declare const defaultHistoryType = "browser";
3
+ export declare const qiankunStateForSlaveModelNamespace = "@@qiankunStateForSlave";
4
+ export declare const qiankunStateFromMasterModelNamespace = "@@qiankunStateFromMaster";
5
+ export declare const MODEL_EXPORT_NAME = "useQiankunStateForSlave";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MODEL_EXPORT_NAME = exports.qiankunStateFromMasterModelNamespace = exports.qiankunStateForSlaveModelNamespace = exports.defaultHistoryType = exports.defaultMasterRootId = void 0;
4
+ exports.defaultMasterRootId = 'root-master';
5
+ exports.defaultHistoryType = 'browser';
6
+ exports.qiankunStateForSlaveModelNamespace = '@@qiankunStateForSlave';
7
+ exports.qiankunStateFromMasterModelNamespace = '@@qiankunStateFromMaster';
8
+ exports.MODEL_EXPORT_NAME = 'useQiankunStateForSlave';
@@ -0,0 +1,6 @@
1
+ import { IApi } from 'umi';
2
+ export declare function isMasterEnable(opts: {
3
+ userConfig: any;
4
+ }): boolean;
5
+ declare const _default: (api: IApi) => void;
6
+ export default _default;
@@ -0,0 +1,114 @@
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 withTmpPath_1 = require("../utils/withTmpPath");
7
+ const constants_1 = require("./constants");
8
+ function isMasterEnable(opts) {
9
+ var _a;
10
+ const masterCfg = (_a = opts.userConfig.qiankun) === null || _a === void 0 ? void 0 : _a.master;
11
+ if (masterCfg) {
12
+ return masterCfg.enable !== false;
13
+ }
14
+ return !!process.env.INITIAL_QIANKUN_MASTER_OPTIONS;
15
+ }
16
+ exports.isMasterEnable = isMasterEnable;
17
+ exports.default = (api) => {
18
+ api.describe({
19
+ key: 'qiankun-master',
20
+ enableBy: isMasterEnable,
21
+ });
22
+ api.addRuntimePlugin(() => {
23
+ return [(0, withTmpPath_1.withTmpPath)({ api, path: 'masterRuntimePlugin.tsx' })];
24
+ });
25
+ api.modifyDefaultConfig((config) => (Object.assign(Object.assign({}, config), { mountElementId: constants_1.defaultMasterRootId, qiankun: Object.assign(Object.assign({}, config.qiankun), { master: Object.assign(Object.assign({}, JSON.parse(process.env.INITIAL_QIANKUN_MASTER_OPTIONS || '{}')), (config.qiankun || {}).master) }) })));
26
+ // TODO: modify routes
27
+ api.modifyRoutes((memo) => {
28
+ Object.keys(memo).forEach((id) => {
29
+ const route = memo[id];
30
+ if (route.microApp) {
31
+ const appName = route.microApp;
32
+ // TODO: config base
33
+ const base = '/';
34
+ // TODO: config masterHistoryType
35
+ const masterHistoryType = 'browser';
36
+ const routeProps = route.microAppProps || {};
37
+ const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
38
+ route.file = `(async () => {
39
+ const { getMicroAppRouteComponent } = await import('@@/plugin-qiankun-master/getMicroAppRouteComponent');
40
+ return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
41
+ })()`;
42
+ }
43
+ });
44
+ return memo;
45
+ });
46
+ // state model for slave app
47
+ api.addRuntimePluginKey(() => [constants_1.MODEL_EXPORT_NAME]);
48
+ api.register({
49
+ key: 'addExtraModels',
50
+ fn() {
51
+ const { path, exports } = api.appData.appJS || {};
52
+ return path && exports.includes(constants_1.MODEL_EXPORT_NAME)
53
+ ? [
54
+ `${path}#{"namespace":"${constants_1.qiankunStateForSlaveModelNamespace}","exportName":"${constants_1.MODEL_EXPORT_NAME}"}`,
55
+ ]
56
+ : [];
57
+ },
58
+ });
59
+ function getFileContent(file) {
60
+ return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/master', file), 'utf-8');
61
+ }
62
+ api.onGenerateFiles(() => {
63
+ var _a;
64
+ api.writeTmpFile({
65
+ path: 'masterOptions.ts',
66
+ content: `
67
+ let options = ${JSON.stringify(Object.assign({ masterHistoryType: ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || constants_1.defaultHistoryType, base: api.config.base || '/' }, api.config.qiankun.master))};
68
+ export const getMasterOptions = () => options;
69
+ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts });
70
+ `,
71
+ });
72
+ api.writeTmpFile({
73
+ path: 'MicroAppLoader.tsx',
74
+ // 开启了 antd 插件的时候,使用 antd 的 loader 组件,否则提示用户必须设置一个自定义的 loader 组件
75
+ content: api.isPluginEnable('antd')
76
+ ? getFileContent('AntdLoader.tsx')
77
+ : `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; }`,
78
+ });
79
+ [
80
+ 'common.ts',
81
+ 'constants.ts',
82
+ 'types.ts',
83
+ 'masterRuntimePlugin.tsx',
84
+ 'getMicroAppRouteComponent.tsx.tpl',
85
+ 'ErrorBoundary.tsx',
86
+ 'MicroApp.tsx',
87
+ ].forEach((file) => {
88
+ if (file.endsWith('.tpl')) {
89
+ api.writeTmpFile({
90
+ path: file.replace(/\.tpl$/, ''),
91
+ tpl: getFileContent(file),
92
+ context: {
93
+ runtimeHistory: api.config.runtimeHistory,
94
+ dynamicRoot: false,
95
+ hasModelPlugin: api.isPluginEnable('model'),
96
+ // dynamicRoot:
97
+ // api.config.exportStatic && api.config.exportStatic.dynamicRoot,
98
+ },
99
+ });
100
+ }
101
+ else {
102
+ api.writeTmpFile({
103
+ path: file.replace(/\.tpl$/, ''),
104
+ content: getFileContent(file)
105
+ .replace('__USE_MODEL__', api.isPluginEnable('model')
106
+ ? `import { useModel } from '@@/plugin-model'`
107
+ : `const useModel = null;`)
108
+ .replace(/from 'qiankun'/g, `from '${(0, path_1.dirname)(require.resolve('qiankun/package'))}'`)
109
+ .replace(/from 'lodash\//g, `from '${(0, path_1.dirname)(require.resolve('lodash/package'))}/`),
110
+ });
111
+ }
112
+ });
113
+ });
114
+ };
@@ -0,0 +1,3 @@
1
+ import { IApi } from 'umi';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;