ssr-plugin-react 6.2.17 → 6.2.18

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [6.2.18](https://github.com/zhangyuang/ssr/compare/plugin-react@6.2.17...plugin-react@6.2.18) (2022-05-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add prefix output to window.prefix in csr mode ([#197](https://github.com/zhangyuang/ssr/issues/197)) ([479bb3d](https://github.com/zhangyuang/ssr/commit/479bb3df67d7da5635939a4219b5f5f9a40b5508))
7
+ * build html ([83be7be](https://github.com/zhangyuang/ssr/commit/83be7be185985a5dcbb9b8e846a5e2b14b94c1b0))
8
+ * build html ([59a8d7f](https://github.com/zhangyuang/ssr/commit/59a8d7f31bed703601e753d02db49ea5a0f93054))
9
+ * plugin-react without dynamic mode ([487cc84](https://github.com/zhangyuang/ssr/commit/487cc84188640aab13c27214df758da0d19e4368))
10
+
11
+
12
+ ### Features
13
+
14
+ * add .vue to defaultWhiteList ([dbabfa2](https://github.com/zhangyuang/ssr/commit/dbabfa2864ec0a5487aadc31286da5630a8603fc))
15
+ * add `turbo` ([#196](https://github.com/zhangyuang/ssr/issues/196)) ([2be17bb](https://github.com/zhangyuang/ssr/commit/2be17bba5d80610b97b3813b3d4fe9579f88e5c3))
16
+ * babelExtraModule support vue ([06251e7](https://github.com/zhangyuang/ssr/commit/06251e716678e1f882f06f68f72c518a341de0d7))
17
+ * babelExtraModule support vue ([513073d](https://github.com/zhangyuang/ssr/commit/513073ddcecbb728d34eae233686a93d63355e00))
18
+ * update turbo ([9ee14f5](https://github.com/zhangyuang/ssr/commit/9ee14f59359187e35f4ef990998846ac3847347b))
19
+ * use terser minify plugin-react server bundle ([0a3c7fe](https://github.com/zhangyuang/ssr/commit/0a3c7fe61908fe24bcb2d8c6394daf2afd18ba82))
20
+
21
+
22
+
1
23
  ## [6.2.17](https://github.com/zhangyuang/ssr/compare/plugin-react@6.2.16...plugin-react@6.2.17) (2022-05-05)
2
24
 
3
25
 
@@ -8,6 +8,7 @@ const base_1 = require("./base");
8
8
  const getServerWebpack = (chain) => {
9
9
  const config = (0, ssr_server_utils_1.loadConfig)();
10
10
  const { isDev, cwd, getOutput, chainServerConfig, whiteList, chunkName } = config;
11
+ const shouldUseSourceMap = isDev || Boolean(process.env.GENERATE_SOURCEMAP);
11
12
  (0, base_1.getBaseConfig)(chain, true);
12
13
  chain.devtool(isDev ? 'inline-source-map' : false);
13
14
  chain.target('node');
@@ -25,6 +26,18 @@ const getServerWebpack = (chain) => {
25
26
  // externals Dir contains example/xxx/node_modules ssr/node_modules
26
27
  modulesDir
27
28
  }));
29
+ if (!isDev) {
30
+ chain.optimization.minimizer('terser')
31
+ .use((0, ssr_server_utils_1.loadModuleFromFramework)('terser-webpack-plugin'), [{
32
+ terserOptions: {
33
+ keep_fnames: true
34
+ },
35
+ extractComments: false,
36
+ parallel: true,
37
+ cache: true,
38
+ sourceMap: shouldUseSourceMap
39
+ }]);
40
+ }
28
41
  chain.when(isDev, () => {
29
42
  chain.watch(true);
30
43
  });
@@ -42,7 +42,7 @@ const serverRender = async (ctx, config) => {
42
42
  injectScript
43
43
  };
44
44
  const isCsr = !!(mode === 'csr' || ((_a = ctx.request.query) === null || _a === void 0 ? void 0 : _a.csr));
45
- const Component = isCsr ? React.Fragment : (await component()).default;
45
+ const Component = isCsr ? React.Fragment : (component.name === 'dynamicComponent' ? (await component()).default : component);
46
46
  if (isCsr) {
47
47
  (0, ssr_server_utils_1.logGreen)(`Current path ${path} use csr render mode`);
48
48
  }
@@ -63,7 +63,7 @@ const serverRender = async (ctx, config) => {
63
63
  }
64
64
  }
65
65
  const combineData = isCsr ? null : Object.assign(state !== null && state !== void 0 ? state : {}, layoutFetchData !== null && layoutFetchData !== void 0 ? layoutFetchData : {}, fetchData !== null && fetchData !== void 0 ? fetchData : {});
66
- const injectState = isCsr ? null : React.createElement("script", { dangerouslySetInnerHTML: {
66
+ const injectState = isCsr ? React.createElement("script", { dangerouslySetInnerHTML: { __html: `window.prefix="${prefix}"` } }) : React.createElement("script", { dangerouslySetInnerHTML: {
67
67
  __html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${(0, ssr_serialize_javascript_1.serialize)(combineData)}; window.prefix="${prefix}";${clientPrefix && `window.clientPrefix="${clientPrefix}"`}`
68
68
  } });
69
69
  return (React.createElement(react_router_dom_1.StaticRouter, { location: ctx.request.url },
package/cjs/tools/vite.js CHANGED
@@ -39,6 +39,9 @@ const serverConfig = {
39
39
  (_g = (_f = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _f === void 0 ? void 0 : _f.server) === null || _g === void 0 ? void 0 : _g.extraPlugin,
40
40
  (0, vite_plugin_style_import_1.default)(styleImportConfig)
41
41
  ],
42
+ esbuild: {
43
+ keepNames: true
44
+ },
42
45
  build: {
43
46
  ssr: reactServerEntry,
44
47
  outDir: serverOutPut,
@@ -1,10 +1,11 @@
1
1
  import { join } from 'path';
2
- import { loadConfig, getLocalNodeModules, nodeExternals } from 'ssr-server-utils';
2
+ import { loadConfig, getLocalNodeModules, nodeExternals, loadModuleFromFramework } from 'ssr-server-utils';
3
3
  import * as webpack from 'webpack';
4
4
  import { getBaseConfig } from './base';
5
5
  const getServerWebpack = (chain) => {
6
6
  const config = loadConfig();
7
7
  const { isDev, cwd, getOutput, chainServerConfig, whiteList, chunkName } = config;
8
+ const shouldUseSourceMap = isDev || Boolean(process.env.GENERATE_SOURCEMAP);
8
9
  getBaseConfig(chain, true);
9
10
  chain.devtool(isDev ? 'inline-source-map' : false);
10
11
  chain.target('node');
@@ -22,6 +23,18 @@ const getServerWebpack = (chain) => {
22
23
  // externals Dir contains example/xxx/node_modules ssr/node_modules
23
24
  modulesDir
24
25
  }));
26
+ if (!isDev) {
27
+ chain.optimization.minimizer('terser')
28
+ .use(loadModuleFromFramework('terser-webpack-plugin'), [{
29
+ terserOptions: {
30
+ keep_fnames: true
31
+ },
32
+ extractComments: false,
33
+ parallel: true,
34
+ cache: true,
35
+ sourceMap: shouldUseSourceMap
36
+ }]);
37
+ }
25
38
  chain.when(isDev, () => {
26
39
  chain.watch(true);
27
40
  });
@@ -39,7 +39,7 @@ const serverRender = async (ctx, config) => {
39
39
  injectScript
40
40
  };
41
41
  const isCsr = !!(mode === 'csr' || ((_a = ctx.request.query) === null || _a === void 0 ? void 0 : _a.csr));
42
- const Component = isCsr ? React.Fragment : (await component()).default;
42
+ const Component = isCsr ? React.Fragment : (component.name === 'dynamicComponent' ? (await component()).default : component);
43
43
  if (isCsr) {
44
44
  logGreen(`Current path ${path} use csr render mode`);
45
45
  }
@@ -60,7 +60,7 @@ const serverRender = async (ctx, config) => {
60
60
  }
61
61
  }
62
62
  const combineData = isCsr ? null : Object.assign(state !== null && state !== void 0 ? state : {}, layoutFetchData !== null && layoutFetchData !== void 0 ? layoutFetchData : {}, fetchData !== null && fetchData !== void 0 ? fetchData : {});
63
- const injectState = isCsr ? null : React.createElement("script", { dangerouslySetInnerHTML: {
63
+ const injectState = isCsr ? React.createElement("script", { dangerouslySetInnerHTML: { __html: `window.prefix="${prefix}"` } }) : React.createElement("script", { dangerouslySetInnerHTML: {
64
64
  __html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}; window.prefix="${prefix}";${clientPrefix && `window.clientPrefix="${clientPrefix}"`}`
65
65
  } });
66
66
  return (React.createElement(StaticRouter, { location: ctx.request.url },
package/esm/tools/vite.js CHANGED
@@ -36,6 +36,9 @@ const serverConfig = {
36
36
  (_g = (_f = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _f === void 0 ? void 0 : _f.server) === null || _g === void 0 ? void 0 : _g.extraPlugin,
37
37
  styleImport(styleImportConfig)
38
38
  ],
39
+ esbuild: {
40
+ keepNames: true
41
+ },
39
42
  build: {
40
43
  ssr: reactServerEntry,
41
44
  outDir: serverOutPut,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssr-plugin-react",
3
- "version": "6.2.17",
3
+ "version": "6.2.18",
4
4
  "description": "plugin-react for ssr",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -1,5 +1,5 @@
1
1
  import { join } from 'path'
2
- import { loadConfig, getLocalNodeModules, nodeExternals } from 'ssr-server-utils'
2
+ import { loadConfig, getLocalNodeModules, nodeExternals, loadModuleFromFramework } from 'ssr-server-utils'
3
3
  import * as WebpackChain from 'webpack-chain'
4
4
  import * as webpack from 'webpack'
5
5
  import { getBaseConfig } from './base'
@@ -7,6 +7,7 @@ import { getBaseConfig } from './base'
7
7
  const getServerWebpack = (chain: WebpackChain) => {
8
8
  const config = loadConfig()
9
9
  const { isDev, cwd, getOutput, chainServerConfig, whiteList, chunkName } = config
10
+ const shouldUseSourceMap = isDev || Boolean(process.env.GENERATE_SOURCEMAP)
10
11
  getBaseConfig(chain, true)
11
12
  chain.devtool(isDev ? 'inline-source-map' : false)
12
13
  chain.target('node')
@@ -25,7 +26,18 @@ const getServerWebpack = (chain: WebpackChain) => {
25
26
  // externals Dir contains example/xxx/node_modules ssr/node_modules
26
27
  modulesDir
27
28
  }))
28
-
29
+ if (!isDev) {
30
+ chain.optimization.minimizer('terser')
31
+ .use(loadModuleFromFramework('terser-webpack-plugin'), [{
32
+ terserOptions: {
33
+ keep_fnames: true
34
+ },
35
+ extractComments: false,
36
+ parallel: true,
37
+ cache: true,
38
+ sourceMap: shouldUseSourceMap
39
+ }])
40
+ }
29
41
  chain.when(isDev, () => {
30
42
  chain.watch(true)
31
43
  })
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react'
2
2
  import { StaticRouter } from 'react-router-dom'
3
3
  import { findRoute, getManifest, logGreen, normalizePath, getAsyncCssChunk, getAsyncJsChunk, reactRefreshFragment } from 'ssr-server-utils'
4
- import { ISSRContext, IConfig, ReactRoutesType, ReactESMFeRouteItem } from 'ssr-types-react'
4
+ import { ISSRContext, IConfig, ReactRoutesType, ReactESMPreloadFeRouteItem, DynamicFC, StaticFC } from 'ssr-types-react'
5
5
  import { serialize } from 'ssr-serialize-javascript'
6
6
  // @ts-expect-error
7
7
  import { STORE_CONTEXT as Context } from '_build/create-context'
@@ -12,7 +12,7 @@ const { FeRoutes, layoutFetch, state, Layout } = Routes as ReactRoutesType
12
12
  const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.ReactElement> => {
13
13
  const { mode, parallelFetch, prefix, isVite, isDev, clientPrefix } = config
14
14
  const path = normalizePath(ctx.request.path, prefix)
15
- const routeItem = findRoute<ReactESMFeRouteItem>(FeRoutes, path)
15
+ const routeItem = findRoute<ReactESMPreloadFeRouteItem>(FeRoutes, path)
16
16
 
17
17
  if (!routeItem) {
18
18
  throw new Error(`
@@ -46,7 +46,7 @@ const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.Re
46
46
  }
47
47
 
48
48
  const isCsr = !!(mode === 'csr' || ctx.request.query?.csr)
49
- const Component = isCsr ? React.Fragment : (await component()).default
49
+ const Component = isCsr ? React.Fragment : (component.name === 'dynamicComponent' ? (await (component as DynamicFC)()).default : component as StaticFC)
50
50
 
51
51
  if (isCsr) {
52
52
  logGreen(`Current path ${path} use csr render mode`)
@@ -68,7 +68,7 @@ const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.Re
68
68
  }
69
69
  }
70
70
  const combineData = isCsr ? null : Object.assign(state ?? {}, layoutFetchData ?? {}, fetchData ?? {})
71
- const injectState = isCsr ? null : <script dangerouslySetInnerHTML={{
71
+ const injectState = isCsr ? <script dangerouslySetInnerHTML={{ __html: `window.prefix="${prefix}"` }} /> : <script dangerouslySetInnerHTML={{
72
72
  __html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}; window.prefix="${prefix}";${clientPrefix && `window.clientPrefix="${clientPrefix}"`}`
73
73
  }} />
74
74
 
package/src/tools/vite.ts CHANGED
@@ -35,6 +35,9 @@ const serverConfig: UserConfig = {
35
35
  viteConfig?.()?.server?.extraPlugin,
36
36
  styleImport(styleImportConfig)
37
37
  ],
38
+ esbuild: {
39
+ keepNames: true
40
+ },
38
41
  build: {
39
42
  ssr: reactServerEntry,
40
43
  outDir: serverOutPut,