@umijs/plugins 4.2.15 → 4.3.0

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.
@@ -65,7 +65,7 @@ export default function InitialStateProvider(props: any) {
65
65
  appLoaded.current = true;
66
66
  }
67
67
  }, [loading]);
68
- if (loading && !appLoaded.current) {
68
+ if (loading && !appLoaded.current && typeof window !== 'undefined') {
69
69
  return <Loading />;
70
70
  }
71
71
  return props.children;
@@ -219,6 +219,16 @@ export { MicroAppWithMemoHistory } from './MicroAppWithMemoHistory';
219
219
  `
220
220
  });
221
221
  });
222
+ api.chainWebpack((config, { ssr }) => {
223
+ if (ssr) {
224
+ const originalExternals = config.get("externals");
225
+ config.externals({
226
+ ...originalExternals,
227
+ qiankun: "fs"
228
+ });
229
+ }
230
+ return config;
231
+ });
222
232
  };
223
233
  // Annotate the CommonJS export names for ESM import in node:
224
234
  0 && (module.exports = {
@@ -171,7 +171,10 @@ export interface IRuntimeConfig {
171
171
  `window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || "/"}";`
172
172
  ];
173
173
  });
174
- api.chainWebpack((config) => {
174
+ api.chainWebpack((config, { ssr }) => {
175
+ if (ssr) {
176
+ return;
177
+ }
175
178
  (0, import_assert.default)(api.pkg.name, "You should have name in package.json.");
176
179
  const {
177
180
  shouldNotAddLibraryChunkName = api.env === "production" || !Boolean(api.config.mfsu)
@@ -201,11 +204,14 @@ export interface IRuntimeConfig {
201
204
  });
202
205
  api.addEntryCode(() => [
203
206
  `
204
- export const bootstrap = qiankun_genBootstrap(render);
205
- export const mount = qiankun_genMount('${api.config.mountElementId}');
206
- export const unmount = qiankun_genUnmount('${api.config.mountElementId}');
207
- export const update = qiankun_genUpdate();
208
- if (!window.__POWERED_BY_QIANKUN__) {
207
+ const qiankun_noop = () => new Error('qiankun lifecycle is not available for server runtime!');
208
+ const isServer = typeof window === 'undefined';
209
+ export const bootstrap = isServer ? qiankun_noop: qiankun_genBootstrap(render);
210
+ export const mount = isServer ? qiankun_noop : qiankun_genMount('${api.config.mountElementId}');
211
+ export const unmount = isServer ? qiankun_noop : qiankun_genUnmount('${api.config.mountElementId}');
212
+ export const update = isServer ? qiankun_noop : qiankun_genUpdate();
213
+ // 增加 ssr 的判断
214
+ if (!isServer && !window.__POWERED_BY_QIANKUN__) {
209
215
  bootstrap().then(mount);
210
216
  }
211
217
  `
@@ -77,6 +77,10 @@ function patchMicroAppRouteComponent(routes: any[]) {
77
77
  }
78
78
 
79
79
  export async function render(oldRender: typeof noop) {
80
+ // 在 ssr 的场景下,直接返回旧的 render
81
+ if (typeof window === 'undefined') {
82
+ return oldRender();
83
+ }
80
84
  const runtimeOptions = await getMasterRuntime();
81
85
  let masterOptions: MasterOptions = {
82
86
  ...getMasterOptions(),
@@ -138,6 +142,10 @@ export async function render(oldRender: typeof noop) {
138
142
  }
139
143
 
140
144
  export function patchClientRoutes({ routes }: { routes: any[] }) {
145
+ // 在 ssr 的场景下,不执行主应用的 patchClientRoutes
146
+ if (typeof window === 'undefined') {
147
+ return;
148
+ }
141
149
  const microAppRoutes = [].concat(
142
150
  deepFilterLeafRoutes(routes),
143
151
  deepFilterLeafRoutes(microAppRuntimeRoutes),
@@ -3,6 +3,10 @@ import { createHistory } from '@@/core/history';
3
3
  import qiankunRender, { contextOptsStack } from './lifecycles';
4
4
 
5
5
  export function render(oldRender: any) {
6
+ // 在 ssr 的场景下,直接返回旧的 render
7
+ if (typeof window === 'undefined') {
8
+ return oldRender();
9
+ }
6
10
  return qiankunRender().then(oldRender);
7
11
  }
8
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.2.15",
3
+ "version": "4.3.0",
4
4
  "description": "@umijs/plugins",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -45,12 +45,12 @@
45
45
  "styled-components": "6.1.1",
46
46
  "tslib": "^2",
47
47
  "warning": "^4.0.3",
48
- "@umijs/bundler-utils": "4.2.15",
48
+ "@umijs/bundler-utils": "4.3.0",
49
49
  "@umijs/valtio": "1.0.4"
50
50
  },
51
51
  "devDependencies": {
52
52
  "antd": "^4.24.1",
53
- "umi": "4.2.15"
53
+ "umi": "4.3.0"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"