ssr-plugin-react 6.2.10 → 6.2.13

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.
@@ -79,6 +79,13 @@ const getBaseConfig = (chain, isServer) => {
79
79
  .exclude
80
80
  .add(/node_modules|core-js/)
81
81
  .end();
82
+ chain.module
83
+ .rule('mjs')
84
+ .test(/\.mjs/)
85
+ .include
86
+ .add(/node_modules/).end()
87
+ .type('javascript/auto')
88
+ .end();
82
89
  const module = chain.module
83
90
  .rule('compileBabelForExtraModule')
84
91
  .test(/\.(js|mjs|jsx|ts|tsx)$/)
@@ -15,7 +15,7 @@ const { FeRoutes, layoutFetch, PrefixRouterBase, state } = create_router_1.Route
15
15
  const serialize = serializeWrap.default || serializeWrap;
16
16
  const serverRender = async (ctx, config) => {
17
17
  var _a;
18
- const { cssOrder, jsOrder, dynamic, mode, parallelFetch, disableClientRender, prefix, isVite, isDev, clientPrefix } = config;
18
+ const { mode, parallelFetch, disableClientRender, prefix, isVite, isDev, clientPrefix } = config;
19
19
  let path = ctx.request.path; // 这里取 pathname 不能够包含 queryString
20
20
  const base = prefix !== null && prefix !== void 0 ? prefix : PrefixRouterBase; // 以开发者实际传入的为最高优先级
21
21
  if (base) {
@@ -28,14 +28,9 @@ const serverRender = async (ctx, config) => {
28
28
  If you create new folder or component file, please restart server by npm start
29
29
  `);
30
30
  }
31
- let dynamicCssOrder = cssOrder;
32
- if (dynamic) {
33
- dynamicCssOrder = cssOrder.concat([`${routeItem.webpackChunkName}.css`]);
34
- if (!isVite || (isVite && !isDev)) {
35
- // call it when webpack mode or vite prod mode
36
- dynamicCssOrder = await (0, ssr_server_utils_1.addAsyncChunk)(dynamicCssOrder, routeItem.webpackChunkName);
37
- }
38
- }
31
+ const { fetch, webpackChunkName, component } = routeItem;
32
+ const dynamicCssOrder = await (0, ssr_server_utils_1.getAsyncCssChunk)(ctx, webpackChunkName);
33
+ const dynamicJsOrder = await (0, ssr_server_utils_1.getAsyncJsChunk)(ctx);
39
34
  const manifest = await (0, ssr_server_utils_1.getManifest)(config);
40
35
  const injectCss = [];
41
36
  if (isVite && isDev) {
@@ -66,14 +61,13 @@ const serverRender = async (ctx, config) => {
66
61
  __html: 'window.__USE_VITE__=true'
67
62
  } }),
68
63
  (isVite && isDev) && React.createElement("script", { type: "module", src: '/node_modules/ssr-plugin-react/esm/entry/client-entry.js', key: "vite-react-entry" }),
69
- ...jsOrder.map(js => manifest[js]).map(item => item && React.createElement("script", { key: item, src: item, type: isVite ? 'module' : '' }))
64
+ ...dynamicJsOrder.map(js => manifest[js]).map(item => item && React.createElement("script", { key: item, src: item, type: isVite ? 'module' : '' }))
70
65
  ];
71
66
  const staticList = {
72
67
  injectCss,
73
68
  injectScript
74
69
  };
75
70
  const isCsr = !!(mode === 'csr' || ((_a = ctx.request.query) === null || _a === void 0 ? void 0 : _a.csr));
76
- const { component, fetch } = routeItem;
77
71
  const Component = isCsr ? React.Fragment : (await component()).default;
78
72
  if (isCsr) {
79
73
  (0, ssr_server_utils_1.logGreen)(`Current path ${path} use csr render mode`);
package/cjs/tools/vite.js CHANGED
@@ -6,7 +6,7 @@ const vite_1 = require("vite");
6
6
  const ssr_server_utils_1 = require("ssr-server-utils");
7
7
  const plugin_react_1 = require("@vitejs/plugin-react");
8
8
  const vite_plugin_style_import_1 = require("vite-plugin-style-import");
9
- const { getOutput, prefix, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev, define, babelOptions } = (0, ssr_server_utils_1.loadConfig)();
9
+ const { getOutput, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev, define, babelOptions } = (0, ssr_server_utils_1.loadConfig)();
10
10
  const { clientOutPut, serverOutPut } = getOutput();
11
11
  const styleImportConfig = {
12
12
  include: ['**/*.vue', '**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx', /chunkName/],
@@ -51,14 +51,14 @@ const serverConfig = {
51
51
  },
52
52
  define: {
53
53
  __isBrowser__: false,
54
- ...define === null || define === void 0 ? void 0 : define.server,
55
- ...define === null || define === void 0 ? void 0 : define.base
54
+ ...define === null || define === void 0 ? void 0 : define.base,
55
+ ...define === null || define === void 0 ? void 0 : define.server
56
56
  }
57
57
  };
58
58
  exports.serverConfig = serverConfig;
59
59
  const clientConfig = {
60
60
  ...(0, ssr_server_utils_1.commonConfig)(),
61
- base: isDev ? '/' : prefix,
61
+ base: isDev ? '/' : (0, ssr_server_utils_1.getOutputPublicPath)(),
62
62
  esbuild: {
63
63
  keepNames: true
64
64
  },
@@ -83,8 +83,8 @@ const clientConfig = {
83
83
  },
84
84
  define: {
85
85
  __isBrowser__: true,
86
- ...define === null || define === void 0 ? void 0 : define.client,
87
- ...define === null || define === void 0 ? void 0 : define.base
86
+ ...define === null || define === void 0 ? void 0 : define.base,
87
+ ...define === null || define === void 0 ? void 0 : define.client
88
88
  }
89
89
  };
90
90
  exports.clientConfig = clientConfig;
@@ -76,6 +76,13 @@ const getBaseConfig = (chain, isServer) => {
76
76
  .exclude
77
77
  .add(/node_modules|core-js/)
78
78
  .end();
79
+ chain.module
80
+ .rule('mjs')
81
+ .test(/\.mjs/)
82
+ .include
83
+ .add(/node_modules/).end()
84
+ .type('javascript/auto')
85
+ .end();
79
86
  const module = chain.module
80
87
  .rule('compileBabelForExtraModule')
81
88
  .test(/\.(js|mjs|jsx|ts|tsx)$/)
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { StaticRouter } from 'react-router-dom';
3
- import { findRoute, getManifest, logGreen, normalizePath, addAsyncChunk } from 'ssr-server-utils';
3
+ import { findRoute, getManifest, logGreen, normalizePath, getAsyncCssChunk, getAsyncJsChunk } from 'ssr-server-utils';
4
4
  // @ts-expect-error
5
5
  import * as serializeWrap from 'serialize-javascript';
6
6
  // @ts-expect-error
@@ -12,7 +12,7 @@ const { FeRoutes, layoutFetch, PrefixRouterBase, state } = Routes;
12
12
  const serialize = serializeWrap.default || serializeWrap;
13
13
  const serverRender = async (ctx, config) => {
14
14
  var _a;
15
- const { cssOrder, jsOrder, dynamic, mode, parallelFetch, disableClientRender, prefix, isVite, isDev, clientPrefix } = config;
15
+ const { mode, parallelFetch, disableClientRender, prefix, isVite, isDev, clientPrefix } = config;
16
16
  let path = ctx.request.path; // 这里取 pathname 不能够包含 queryString
17
17
  const base = prefix !== null && prefix !== void 0 ? prefix : PrefixRouterBase; // 以开发者实际传入的为最高优先级
18
18
  if (base) {
@@ -25,14 +25,9 @@ const serverRender = async (ctx, config) => {
25
25
  If you create new folder or component file, please restart server by npm start
26
26
  `);
27
27
  }
28
- let dynamicCssOrder = cssOrder;
29
- if (dynamic) {
30
- dynamicCssOrder = cssOrder.concat([`${routeItem.webpackChunkName}.css`]);
31
- if (!isVite || (isVite && !isDev)) {
32
- // call it when webpack mode or vite prod mode
33
- dynamicCssOrder = await addAsyncChunk(dynamicCssOrder, routeItem.webpackChunkName);
34
- }
35
- }
28
+ const { fetch, webpackChunkName, component } = routeItem;
29
+ const dynamicCssOrder = await getAsyncCssChunk(ctx, webpackChunkName);
30
+ const dynamicJsOrder = await getAsyncJsChunk(ctx);
36
31
  const manifest = await getManifest(config);
37
32
  const injectCss = [];
38
33
  if (isVite && isDev) {
@@ -63,14 +58,13 @@ const serverRender = async (ctx, config) => {
63
58
  __html: 'window.__USE_VITE__=true'
64
59
  } }),
65
60
  (isVite && isDev) && React.createElement("script", { type: "module", src: '/node_modules/ssr-plugin-react/esm/entry/client-entry.js', key: "vite-react-entry" }),
66
- ...jsOrder.map(js => manifest[js]).map(item => item && React.createElement("script", { key: item, src: item, type: isVite ? 'module' : '' }))
61
+ ...dynamicJsOrder.map(js => manifest[js]).map(item => item && React.createElement("script", { key: item, src: item, type: isVite ? 'module' : '' }))
67
62
  ];
68
63
  const staticList = {
69
64
  injectCss,
70
65
  injectScript
71
66
  };
72
67
  const isCsr = !!(mode === 'csr' || ((_a = ctx.request.query) === null || _a === void 0 ? void 0 : _a.csr));
73
- const { component, fetch } = routeItem;
74
68
  const Component = isCsr ? React.Fragment : (await component()).default;
75
69
  if (isCsr) {
76
70
  logGreen(`Current path ${path} use csr render mode`);
package/esm/tools/vite.js CHANGED
@@ -1,9 +1,9 @@
1
1
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
2
2
  import { build } from 'vite';
3
- import { loadConfig, chunkNamePlugin, rollupOutputOptions, manifestPlugin, commonConfig, asyncOptimizeChunkPlugin } from 'ssr-server-utils';
3
+ import { loadConfig, chunkNamePlugin, rollupOutputOptions, manifestPlugin, commonConfig, asyncOptimizeChunkPlugin, getOutputPublicPath } from 'ssr-server-utils';
4
4
  import react from '@vitejs/plugin-react';
5
5
  import styleImport, { AndDesignVueResolve, VantResolve, ElementPlusResolve, NutuiResolve, AntdResolve } from 'vite-plugin-style-import';
6
- const { getOutput, prefix, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev, define, babelOptions } = loadConfig();
6
+ const { getOutput, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev, define, babelOptions } = loadConfig();
7
7
  const { clientOutPut, serverOutPut } = getOutput();
8
8
  const styleImportConfig = {
9
9
  include: ['**/*.vue', '**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx', /chunkName/],
@@ -48,13 +48,13 @@ const serverConfig = {
48
48
  },
49
49
  define: {
50
50
  __isBrowser__: false,
51
- ...define === null || define === void 0 ? void 0 : define.server,
52
- ...define === null || define === void 0 ? void 0 : define.base
51
+ ...define === null || define === void 0 ? void 0 : define.base,
52
+ ...define === null || define === void 0 ? void 0 : define.server
53
53
  }
54
54
  };
55
55
  const clientConfig = {
56
56
  ...commonConfig(),
57
- base: isDev ? '/' : prefix,
57
+ base: isDev ? '/' : getOutputPublicPath(),
58
58
  esbuild: {
59
59
  keepNames: true
60
60
  },
@@ -79,8 +79,8 @@ const clientConfig = {
79
79
  },
80
80
  define: {
81
81
  __isBrowser__: true,
82
- ...define === null || define === void 0 ? void 0 : define.client,
83
- ...define === null || define === void 0 ? void 0 : define.base
82
+ ...define === null || define === void 0 ? void 0 : define.base,
83
+ ...define === null || define === void 0 ? void 0 : define.client
84
84
  }
85
85
  };
86
86
  const viteStart = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssr-plugin-react",
3
- "version": "6.2.10",
3
+ "version": "6.2.13",
4
4
  "description": "plugin-react for ssr",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -35,8 +35,8 @@
35
35
  "@babel/plugin-transform-runtime": "^7.9.6",
36
36
  "@babel/preset-env": "^7.5.5",
37
37
  "@vitejs/plugin-react": "^1.0.0",
38
- "babel-loader": "8.0.4",
39
- "babel-plugin-import": "^1.13.0",
38
+ "babel-loader": "^8.0.4",
39
+ "babel-plugin-import": "1.13.3",
40
40
  "babel-preset-react-app": "^9.0.2",
41
41
  "core-js": "^3.6.4",
42
42
  "css-hot-loader": "^1.4.4",
@@ -53,6 +53,10 @@
53
53
  "postcss-modules": "^4.0.0",
54
54
  "postcss-preset-env": "^7.0.0",
55
55
  "postcss-safe-parser": "^6.0.0",
56
+ "react": "^17.0.1",
57
+ "react-dom": "^17.0.0",
58
+ "react-router": "^5.2.1",
59
+ "react-router-dom": "^5.1.2",
56
60
  "react-dev-utils": "^11.0.4",
57
61
  "serialize-javascript": "^6.0.0",
58
62
  "ssr-client-utils": "^6.2.7",
@@ -63,6 +67,7 @@
63
67
  "url-loader": "^4.1.1",
64
68
  "vite": "^2.7.0",
65
69
  "vite-plugin-style-import": "^1.4.0",
70
+ "webpack": "^4.42.1",
66
71
  "webpack-bundle-analyzer": "^3.6.1",
67
72
  "webpack-chain": "^6.4.0",
68
73
  "webpack-manifest-plugin": "^2.2.0",
@@ -74,7 +79,7 @@
74
79
  "@types/react-router-dom": "^5.1.3",
75
80
  "@types/webpack": "^4.41.10",
76
81
  "concurrently": "^5.1.0",
82
+ "ssr-types": "^6.2.3",
77
83
  "ssr-types-react": "^6.2.7"
78
- },
79
- "gitHead": "5af68df670e62bdcf21c6587f4bce23d30fcf514"
84
+ }
80
85
  }
@@ -85,6 +85,14 @@ const getBaseConfig = (chain: WebpackChain, isServer: boolean) => {
85
85
  .add(/node_modules|core-js/)
86
86
  .end()
87
87
 
88
+ chain.module
89
+ .rule('mjs')
90
+ .test(/\.mjs/)
91
+ .include
92
+ .add(/node_modules/).end()
93
+ .type('javascript/auto')
94
+ .end()
95
+
88
96
  const module = chain.module
89
97
  .rule('compileBabelForExtraModule')
90
98
  .test(/\.(js|mjs|jsx|ts|tsx)$/)
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react'
2
2
  import { StaticRouter } from 'react-router-dom'
3
- import { findRoute, getManifest, logGreen, normalizePath, addAsyncChunk } from 'ssr-server-utils'
3
+ import { findRoute, getManifest, logGreen, normalizePath, getAsyncCssChunk, getAsyncJsChunk } from 'ssr-server-utils'
4
4
  import { ISSRContext, IConfig, ReactRoutesType, ReactESMFeRouteItem } from 'ssr-types-react'
5
5
  // @ts-expect-error
6
6
  import * as serializeWrap from 'serialize-javascript'
@@ -14,7 +14,7 @@ const { FeRoutes, layoutFetch, PrefixRouterBase, state } = Routes as ReactRoutes
14
14
  const serialize = serializeWrap.default || serializeWrap
15
15
 
16
16
  const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.ReactElement> => {
17
- const { cssOrder, jsOrder, dynamic, mode, parallelFetch, disableClientRender, prefix, isVite, isDev, clientPrefix } = config
17
+ const { mode, parallelFetch, disableClientRender, prefix, isVite, isDev, clientPrefix } = config
18
18
  let path = ctx.request.path // 这里取 pathname 不能够包含 queryString
19
19
  const base = prefix ?? PrefixRouterBase // 以开发者实际传入的为最高优先级
20
20
  if (base) {
@@ -29,15 +29,9 @@ const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.Re
29
29
  `)
30
30
  }
31
31
 
32
- let dynamicCssOrder = cssOrder
33
-
34
- if (dynamic) {
35
- dynamicCssOrder = cssOrder.concat([`${routeItem.webpackChunkName}.css`])
36
- if (!isVite || (isVite && !isDev)) {
37
- // call it when webpack mode or vite prod mode
38
- dynamicCssOrder = await addAsyncChunk(dynamicCssOrder, routeItem.webpackChunkName)
39
- }
40
- }
32
+ const { fetch, webpackChunkName, component } = routeItem
33
+ const dynamicCssOrder = await getAsyncCssChunk(ctx, webpackChunkName)
34
+ const dynamicJsOrder = await getAsyncJsChunk(ctx)
41
35
  const manifest = await getManifest(config)
42
36
 
43
37
  const injectCss: JSX.Element[] = []
@@ -71,7 +65,7 @@ const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.Re
71
65
  __html: 'window.__USE_VITE__=true'
72
66
  }} />,
73
67
  (isVite && isDev) && <script type="module" src='/node_modules/ssr-plugin-react/esm/entry/client-entry.js' key="vite-react-entry" />,
74
- ...jsOrder.map(js => manifest[js]).map(item => item && <script key={item} src={item} type={isVite ? 'module' : ''}/>)
68
+ ...dynamicJsOrder.map(js => manifest[js]).map(item => item && <script key={item} src={item} type={isVite ? 'module' : ''}/>)
75
69
  ]
76
70
  const staticList = {
77
71
  injectCss,
@@ -79,7 +73,6 @@ const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.Re
79
73
  }
80
74
 
81
75
  const isCsr = !!(mode === 'csr' || ctx.request.query?.csr)
82
- const { component, fetch } = routeItem
83
76
  const Component = isCsr ? React.Fragment : (await component()).default
84
77
 
85
78
  if (isCsr) {
package/src/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { loadConfig } from 'ssr-server-utils'
2
2
 
3
3
  const { isVite } = loadConfig()
4
-
5
4
  export function clientPlugin () {
6
5
  return {
7
6
  name: 'plugin-react',
package/src/tools/vite.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { build, UserConfig } from 'vite'
2
- import { loadConfig, chunkNamePlugin, rollupOutputOptions, manifestPlugin, commonConfig, asyncOptimizeChunkPlugin } from 'ssr-server-utils'
2
+ import { loadConfig, chunkNamePlugin, rollupOutputOptions, manifestPlugin, commonConfig, asyncOptimizeChunkPlugin, getOutputPublicPath } from 'ssr-server-utils'
3
3
  import react from '@vitejs/plugin-react'
4
4
  import styleImport, { AndDesignVueResolve, VantResolve, ElementPlusResolve, NutuiResolve, AntdResolve } from 'vite-plugin-style-import'
5
-
6
- const { getOutput, prefix, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev, define, babelOptions } = loadConfig()
7
-
5
+ const { getOutput, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev, define, babelOptions } = loadConfig()
8
6
  const { clientOutPut, serverOutPut } = getOutput()
9
7
  const styleImportConfig = {
10
8
  include: ['**/*.vue', '**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx', /chunkName/],
@@ -49,14 +47,14 @@ const serverConfig: UserConfig = {
49
47
  },
50
48
  define: {
51
49
  __isBrowser__: false,
52
- ...define?.server,
53
- ...define?.base
50
+ ...define?.base,
51
+ ...define?.server
54
52
  }
55
53
  }
56
54
 
57
55
  const clientConfig: UserConfig = {
58
56
  ...commonConfig(),
59
- base: isDev ? '/' : prefix,
57
+ base: isDev ? '/' : getOutputPublicPath(),
60
58
  esbuild: {
61
59
  keepNames: true
62
60
  },
@@ -81,8 +79,8 @@ const clientConfig: UserConfig = {
81
79
  },
82
80
  define: {
83
81
  __isBrowser__: true,
84
- ...define?.client,
85
- ...define?.base
82
+ ...define?.base,
83
+ ...define?.client
86
84
  }
87
85
  }
88
86
  const viteStart = async () => {