ssr-plugin-react 5.6.22 → 5.6.26

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
@@ -3,6 +3,41 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [5.6.26](https://github.com/ykfe/ssr/compare/v5.6.25...v5.6.26) (2021-09-29)
7
+
8
+ **Note:** Version bump only for package ssr-plugin-react
9
+
10
+
11
+
12
+
13
+
14
+ ## [5.6.25](https://github.com/ykfe/ssr/compare/v5.6.24...v5.6.25) (2021-09-24)
15
+
16
+ **Note:** Version bump only for package ssr-plugin-react
17
+
18
+
19
+
20
+
21
+
22
+ ## [5.6.24](https://github.com/ykfe/ssr/compare/v5.6.23...v5.6.24) (2021-09-23)
23
+
24
+ **Note:** Version bump only for package ssr-plugin-react
25
+
26
+
27
+
28
+
29
+
30
+ ## [5.6.23](https://github.com/ykfe/ssr/compare/v5.6.22...v5.6.23) (2021-09-23)
31
+
32
+
33
+ ### Features
34
+
35
+ * add limit plugin in server side ([11c70aa](https://github.com/ykfe/ssr/commit/11c70aa2afc49fe5b7fa51ac2c72310ec5f8548f))
36
+
37
+
38
+
39
+
40
+
6
41
  ## [5.6.22](https://github.com/ykfe/ssr/compare/v5.6.20...v5.6.22) (2021-09-13)
7
42
 
8
43
 
package/README.md CHANGED
@@ -256,7 +256,7 @@ $ npm run start:vite # 以 vite 模式启动,等价于 npx ssr start --vite
256
256
 
257
257
  <div style="display:flex">
258
258
  <img src="https://res.wx.qq.com/op_res/rrhdxU0o2yUdgTjwgkAgO-CSFV-lArvMYzWzxl2SuvnKkcWECv7SXswEYjk2pPcDcL43r0kz_MIp_fsxPPqQ2Q" width="300">
259
- <img src="https://res.wx.qq.com/op_res/lbia1Qw5Rdkh9fbMoVM2J85Z8QhPxuD1ZE5kU3GysXxslsA1FTqk4NGuiNo1e2ub7Z5l-63y7jyugQMJxl-DiA" width="300">
259
+ <img src="https://res.wx.qq.com/op_res/vN-ex83t0SUwJWJ_2W2zTkiMcHa7jFeweuROktahorwwGJouTfPAoDeI2TLu1dloWe0oxDQ2O4GAzwqNxiqtlA" width="300">
260
260
  </div>
261
261
 
262
262
  ## 前端开发手册
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getBaseConfig = void 0;
4
4
  const path_1 = require("path");
5
5
  const ssr_server_utils_1 = require("ssr-server-utils");
6
+ const webpack = require("webpack");
6
7
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
7
8
  const WebpackBar = require('webpackbar');
8
9
  const loadModule = require.resolve;
@@ -41,7 +42,7 @@ const addBabelLoader = (chain, envOptions) => {
41
42
  .end();
42
43
  };
43
44
  const getBaseConfig = (chain, isServer) => {
44
- const config = ssr_server_utils_1.loadConfig();
45
+ const config = (0, ssr_server_utils_1.loadConfig)();
45
46
  const { moduleFileExtensions, useHash, isDev, chainBaseConfig, corejs, babelExtraModule } = config;
46
47
  const mode = process.env.NODE_ENV;
47
48
  const envOptions = {
@@ -62,9 +63,9 @@ const getBaseConfig = (chain, isServer) => {
62
63
  .resolve
63
64
  .modules
64
65
  .add('node_modules')
65
- .add(path_1.join(ssr_server_utils_1.getCwd(), './node_modules'))
66
+ .add((0, path_1.join)((0, ssr_server_utils_1.getCwd)(), './node_modules'))
66
67
  .when(isDev, chain => {
67
- chain.add(ssr_server_utils_1.getLocalNodeModules());
68
+ chain.add((0, ssr_server_utils_1.getLocalNodeModules)());
68
69
  })
69
70
  .end()
70
71
  .extensions.merge(moduleFileExtensions)
@@ -72,12 +73,12 @@ const getBaseConfig = (chain, isServer) => {
72
73
  .alias
73
74
  .end();
74
75
  chain.resolve.alias
75
- .set('@', ssr_server_utils_1.getFeDir())
76
- .set('_build', path_1.join(ssr_server_utils_1.getCwd(), './build'))
76
+ .set('@', (0, ssr_server_utils_1.getFeDir)())
77
+ .set('_build', (0, path_1.join)((0, ssr_server_utils_1.getCwd)(), './build'))
77
78
  .set('react', loadModule('react')) // 用cwd的路径alias,否则可能会出现多个react实例
78
79
  .set('react-router', loadModule('react-router'))
79
80
  .set('react-router-dom', loadModule('react-router-dom'));
80
- ssr_server_utils_1.addImageChain(chain, isServer);
81
+ (0, ssr_server_utils_1.addImageChain)(chain, isServer);
81
82
  const babelModule = chain.module
82
83
  .rule('compileBabel')
83
84
  .test(/\.(js|mjs|jsx|ts|tsx)$/)
@@ -98,20 +99,14 @@ const getBaseConfig = (chain, isServer) => {
98
99
  }
99
100
  addBabelLoader(babelModule, envOptions);
100
101
  addBabelLoader(babelForExtraModule, envOptions);
101
- ssr_server_utils_1.setStyle(chain, /\.css$/, {
102
+ (0, ssr_server_utils_1.setStyle)(chain, /\.css$/, {
102
103
  rule: 'css',
103
- modules: {
104
- auto: true
105
- },
106
104
  isServer,
107
105
  importLoaders: 1
108
106
  });
109
- ssr_server_utils_1.setStyle(chain, /\.less$/, {
107
+ (0, ssr_server_utils_1.setStyle)(chain, /\.less$/, {
110
108
  rule: 'less',
111
109
  loader: 'less-loader',
112
- modules: {
113
- auto: true
114
- },
115
110
  isServer,
116
111
  importLoaders: 2
117
112
  });
@@ -144,6 +139,9 @@ const getBaseConfig = (chain, isServer) => {
144
139
  name: isServer ? 'server' : 'client',
145
140
  color: isServer ? '#f173ac' : '#45b97c'
146
141
  }));
142
+ chain.plugin('ssrDefine').use(webpack.DefinePlugin, [{
143
+ __isBrowser__: !isServer
144
+ }]);
147
145
  chainBaseConfig(chain);
148
146
  return config;
149
147
  };
@@ -1,4 +1,4 @@
1
- import * as webpack from 'webpack';
1
+ /// <reference types="webpack" />
2
2
  import * as WebpackChain from 'webpack-chain';
3
- declare const getClientWebpack: (chain: WebpackChain) => webpack.Configuration;
3
+ declare const getClientWebpack: (chain: WebpackChain) => import("webpack").Configuration;
4
4
  export { getClientWebpack };
@@ -4,7 +4,6 @@ exports.getClientWebpack = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const ssr_server_utils_1 = require("ssr-server-utils");
7
- const webpack = require("webpack");
8
7
  const base_1 = require("./base");
9
8
  const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
10
9
  const safePostCssParser = require('postcss-safe-parser');
@@ -13,10 +12,10 @@ const generateAnalysis = Boolean(process.env.GENERATE_ANALYSIS);
13
12
  const loadModule = require.resolve;
14
13
  let asyncChunkMap = {};
15
14
  const getClientWebpack = (chain) => {
16
- const { isDev, chunkName, getOutput, cwd, useHash, chainClientConfig } = ssr_server_utils_1.loadConfig();
15
+ const { isDev, chunkName, getOutput, cwd, useHash, chainClientConfig } = (0, ssr_server_utils_1.loadConfig)();
17
16
  const shouldUseSourceMap = isDev || process.env.GENERATE_SOURCEMAP;
18
- const publicPath = ssr_server_utils_1.getOutputPublicPath();
19
- base_1.getBaseConfig(chain, false);
17
+ const publicPath = (0, ssr_server_utils_1.getOutputPublicPath)();
18
+ (0, base_1.getBaseConfig)(chain, false);
20
19
  chain.devtool(isDev ? 'cheap-module-source-map' : (shouldUseSourceMap ? 'source-map' : false));
21
20
  chain.entry(chunkName)
22
21
  .add(loadModule('../entry/client-entry'))
@@ -32,7 +31,7 @@ const getClientWebpack = (chain) => {
32
31
  .splitChunks({
33
32
  chunks: 'all',
34
33
  name(module, chunks, cacheGroupKey) {
35
- return ssr_server_utils_1.cryptoAsyncChunkName(chunks, asyncChunkMap);
34
+ return (0, ssr_server_utils_1.cryptoAsyncChunkName)(chunks, asyncChunkMap);
36
35
  },
37
36
  cacheGroups: {
38
37
  vendors: {
@@ -83,9 +82,6 @@ const getClientWebpack = (chain) => {
83
82
  }
84
83
  }]);
85
84
  });
86
- chain.plugin('define').use(webpack.DefinePlugin, [{
87
- __isBrowser__: true
88
- }]);
89
85
  chain.plugin('moduleNotFound').use(ModuleNotFoundPlugin, [cwd]);
90
86
  chain.plugin('manifest').use(loadModule('webpack-manifest-plugin'), [{
91
87
  fileName: 'asset-manifest.json'
@@ -100,7 +96,7 @@ const getClientWebpack = (chain) => {
100
96
  asyncChunkMap = {};
101
97
  });
102
98
  compiler.hooks.done.tapAsync('WriteAsyncChunkManifest', async (params, callback) => {
103
- await fs_1.promises.writeFile(path_1.resolve(ssr_server_utils_1.getCwd(), './build/asyncChunkMap.json'), JSON.stringify(asyncChunkMap));
99
+ await fs_1.promises.writeFile((0, path_1.resolve)((0, ssr_server_utils_1.getCwd)(), './build/asyncChunkMap.json'), JSON.stringify(asyncChunkMap));
104
100
  callback();
105
101
  });
106
102
  }
@@ -1,4 +1,4 @@
1
- import * as webpack from 'webpack';
2
1
  import * as WebpackChain from 'webpack-chain';
2
+ import * as webpack from 'webpack';
3
3
  declare const getServerWebpack: (chain: WebpackChain) => webpack.Configuration;
4
4
  export { getServerWebpack };
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getServerWebpack = void 0;
4
4
  const path_1 = require("path");
5
- const webpack = require("webpack");
6
5
  const ssr_server_utils_1 = require("ssr-server-utils");
6
+ const webpack = require("webpack");
7
7
  const base_1 = require("./base");
8
8
  const loadModule = require.resolve;
9
9
  const getServerWebpack = (chain) => {
10
- const config = ssr_server_utils_1.loadConfig();
10
+ const config = (0, ssr_server_utils_1.loadConfig)();
11
11
  const { isDev, cwd, getOutput, chainServerConfig, whiteList, chunkName } = config;
12
- base_1.getBaseConfig(chain, true);
12
+ (0, base_1.getBaseConfig)(chain, true);
13
13
  chain.devtool(isDev ? 'inline-source-map' : false);
14
14
  chain.target('node');
15
15
  chain.entry(chunkName)
@@ -19,9 +19,9 @@ const getServerWebpack = (chain) => {
19
19
  .path(getOutput().serverOutPut)
20
20
  .filename('[name].server.js')
21
21
  .libraryTarget('commonjs');
22
- const modulesDir = [path_1.join(cwd, './node_modules')];
23
- modulesDir.push(ssr_server_utils_1.getLocalNodeModules());
24
- chain.externals(ssr_server_utils_1.nodeExternals({
22
+ const modulesDir = [(0, path_1.join)(cwd, './node_modules')];
23
+ modulesDir.push((0, ssr_server_utils_1.getLocalNodeModules)());
24
+ chain.externals((0, ssr_server_utils_1.nodeExternals)({
25
25
  whitelist: [/\.(css|less|sass|scss)$/, /antd.*?(style)/].concat(whiteList || []),
26
26
  // externals Dir contains example/xxx/node_modules ssr/node_modules
27
27
  modulesDir
@@ -29,8 +29,8 @@ const getServerWebpack = (chain) => {
29
29
  chain.when(isDev, () => {
30
30
  chain.watch(true);
31
31
  });
32
- chain.plugin('define').use(webpack.DefinePlugin, [{
33
- __isBrowser__: false
32
+ chain.plugin('serverLimit').use(webpack.optimize.LimitChunkCountPlugin, [{
33
+ maxChunks: 1
34
34
  }]);
35
35
  chainServerConfig(chain); // 合并用户自定义配置
36
36
  return chain.toConfig();
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.clientRender = void 0;
4
- //@ts-nocheck
5
4
  const React = require("react");
6
5
  const ReactDOM = require("react-dom");
7
6
  const react_router_dom_1 = require("react-router-dom");
@@ -17,7 +16,7 @@ const clientRender = async () => {
17
16
  return props.children;
18
17
  };
19
18
  // 客户端渲染||hydrate
20
- const routes = await ssr_client_utils_1.preloadComponent(FeRoutes, BASE_NAME);
19
+ const routes = await (0, ssr_client_utils_1.preloadComponent)(FeRoutes, BASE_NAME);
21
20
  ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](React.createElement(react_router_dom_1.BrowserRouter, { basename: BASE_NAME },
22
21
  React.createElement(context_1.AppContext, null,
23
22
  React.createElement(react_router_dom_1.Switch, null,
@@ -28,7 +27,7 @@ const clientRender = async () => {
28
27
  const { fetch, component, path } = item;
29
28
  component.fetch = fetch;
30
29
  component.layoutFetch = layoutFetch;
31
- const WrappedComponent = ssr_hoc_react_1.wrapComponent(component);
30
+ const WrappedComponent = (0, ssr_hoc_react_1.wrapComponent)(component);
32
31
  return (React.createElement(react_router_dom_1.Route, { exact: true, key: path, path: path, render: () => React.createElement(WrappedComponent, { key: location.pathname }) }));
33
32
  })))))), document.getElementById('app'));
34
33
  if (!window.__USE_VITE__) {
@@ -26,7 +26,7 @@ function combineReducer(state, action) {
26
26
  return defaultReducer(state, action) || userReducer(state, action);
27
27
  }
28
28
  function AppContext(props) {
29
- const [state, dispatch] = react_1.useReducer(combineReducer, initialState);
29
+ const [state, dispatch] = (0, react_1.useReducer)(combineReducer, initialState);
30
30
  return (React.createElement(create_context_1.clientContext.Provider, { value: { state, dispatch } }, props.children));
31
31
  }
32
32
  exports.AppContext = AppContext;
@@ -4,11 +4,11 @@ exports.clientContext = exports.serverContext = void 0;
4
4
  const react_1 = require("react");
5
5
  // 服务端需要为每一个请求创建全新的 contetx 方式请求污染
6
6
  const serverContext = (context) => {
7
- return react_1.createContext(context);
7
+ return (0, react_1.createContext)(context);
8
8
  };
9
9
  exports.serverContext = serverContext;
10
10
  // 客户端的 context 只需要创建一次,在页面整个生命周期内共享
11
- const clientContext = react_1.createContext({
11
+ const clientContext = (0, react_1.createContext)({
12
12
  state: {}
13
13
  });
14
14
  exports.clientContext = clientContext;
@@ -17,10 +17,10 @@ const serverRender = async (ctx, config) => {
17
17
  global.window = (_a = global.window) !== null && _a !== void 0 ? _a : {}; // 防止覆盖上层应用自己定义的 window 对象
18
18
  let path = ctx.request.path; // 这里取 pathname 不能够包含 queyString
19
19
  if (BASE_NAME) {
20
- path = ssr_server_utils_1.normalizePath(path);
20
+ path = (0, ssr_server_utils_1.normalizePath)(path);
21
21
  }
22
22
  const { window } = global;
23
- const routeItem = ssr_server_utils_1.findRoute(FeRoutes, path);
23
+ const routeItem = (0, ssr_server_utils_1.findRoute)(FeRoutes, path);
24
24
  const viteMode = process.env.BUILD_TOOL === 'vite';
25
25
  if (!routeItem) {
26
26
  throw new Error(`
@@ -31,9 +31,9 @@ const serverRender = async (ctx, config) => {
31
31
  let dynamicCssOrder = cssOrder;
32
32
  if (dynamic && !viteMode) {
33
33
  dynamicCssOrder = cssOrder.concat([`${routeItem.webpackChunkName}.css`]);
34
- dynamicCssOrder = await ssr_server_utils_1.addAsyncChunk(dynamicCssOrder, routeItem.webpackChunkName);
34
+ dynamicCssOrder = await (0, ssr_server_utils_1.addAsyncChunk)(dynamicCssOrder, routeItem.webpackChunkName);
35
35
  }
36
- const manifest = viteMode ? {} : await ssr_server_utils_1.getManifest();
36
+ const manifest = viteMode ? {} : await (0, ssr_server_utils_1.getManifest)();
37
37
  const injectCss = [];
38
38
  if (viteMode) {
39
39
  injectCss.push(React.createElement("script", { src: "/@vite/client", type: "module", key: "vite-client" }));
@@ -74,7 +74,7 @@ const serverRender = async (ctx, config) => {
74
74
  const { component, fetch } = routeItem;
75
75
  const Component = component;
76
76
  if (isCsr) {
77
- ssr_server_utils_1.logGreen(`Current path ${path} use csr render mode`);
77
+ (0, ssr_server_utils_1.logGreen)(`Current path ${path} use csr render mode`);
78
78
  }
79
79
  let layoutFetchData = {};
80
80
  let fetchData = {};
@@ -99,7 +99,7 @@ const serverRender = async (ctx, config) => {
99
99
  const injectState = isCsr ? null : React.createElement("script", { dangerouslySetInnerHTML: {
100
100
  __html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}`
101
101
  } });
102
- const Context = create_context_1.serverContext(combineData); // 服务端需要每个请求创建新的独立的 context
102
+ const Context = (0, create_context_1.serverContext)(combineData); // 服务端需要每个请求创建新的独立的 context
103
103
  window.STORE_CONTEXT = Context; // 为每一个新的请求都创建一遍 context 并且覆盖 window 上的属性,使得无需通过props层层传递读取
104
104
  return (React.createElement(react_router_dom_1.StaticRouter, null,
105
105
  React.createElement(Context.Provider, { value: { state: combineData } },
@@ -1,5 +1,6 @@
1
1
  import { join } from 'path';
2
2
  import { getFeDir, getCwd, loadConfig, getLocalNodeModules, setStyle, addImageChain } from 'ssr-server-utils';
3
+ import * as webpack from 'webpack';
3
4
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4
5
  const WebpackBar = require('webpackbar');
5
6
  const loadModule = require.resolve;
@@ -97,18 +98,12 @@ const getBaseConfig = (chain, isServer) => {
97
98
  addBabelLoader(babelForExtraModule, envOptions);
98
99
  setStyle(chain, /\.css$/, {
99
100
  rule: 'css',
100
- modules: {
101
- auto: true
102
- },
103
101
  isServer,
104
102
  importLoaders: 1
105
103
  });
106
104
  setStyle(chain, /\.less$/, {
107
105
  rule: 'less',
108
106
  loader: 'less-loader',
109
- modules: {
110
- auto: true
111
- },
112
107
  isServer,
113
108
  importLoaders: 2
114
109
  });
@@ -141,6 +136,9 @@ const getBaseConfig = (chain, isServer) => {
141
136
  name: isServer ? 'server' : 'client',
142
137
  color: isServer ? '#f173ac' : '#45b97c'
143
138
  }));
139
+ chain.plugin('ssrDefine').use(webpack.DefinePlugin, [{
140
+ __isBrowser__: !isServer
141
+ }]);
144
142
  chainBaseConfig(chain);
145
143
  return config;
146
144
  };
@@ -1,4 +1,4 @@
1
- import * as webpack from 'webpack';
1
+ /// <reference types="webpack" />
2
2
  import * as WebpackChain from 'webpack-chain';
3
- declare const getClientWebpack: (chain: WebpackChain) => webpack.Configuration;
3
+ declare const getClientWebpack: (chain: WebpackChain) => import("webpack").Configuration;
4
4
  export { getClientWebpack };
@@ -1,7 +1,6 @@
1
1
  import { promises } from 'fs';
2
2
  import { resolve } from 'path';
3
3
  import { loadConfig, getCwd, cryptoAsyncChunkName, getOutputPublicPath } from 'ssr-server-utils';
4
- import * as webpack from 'webpack';
5
4
  import { getBaseConfig } from './base';
6
5
  const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
7
6
  const safePostCssParser = require('postcss-safe-parser');
@@ -80,9 +79,6 @@ const getClientWebpack = (chain) => {
80
79
  }
81
80
  }]);
82
81
  });
83
- chain.plugin('define').use(webpack.DefinePlugin, [{
84
- __isBrowser__: true
85
- }]);
86
82
  chain.plugin('moduleNotFound').use(ModuleNotFoundPlugin, [cwd]);
87
83
  chain.plugin('manifest').use(loadModule('webpack-manifest-plugin'), [{
88
84
  fileName: 'asset-manifest.json'
@@ -1,4 +1,4 @@
1
- import * as webpack from 'webpack';
2
1
  import * as WebpackChain from 'webpack-chain';
2
+ import * as webpack from 'webpack';
3
3
  declare const getServerWebpack: (chain: WebpackChain) => webpack.Configuration;
4
4
  export { getServerWebpack };
@@ -1,6 +1,6 @@
1
1
  import { join } from 'path';
2
- import * as webpack from 'webpack';
3
2
  import { loadConfig, getLocalNodeModules, nodeExternals } from 'ssr-server-utils';
3
+ import * as webpack from 'webpack';
4
4
  import { getBaseConfig } from './base';
5
5
  const loadModule = require.resolve;
6
6
  const getServerWebpack = (chain) => {
@@ -26,8 +26,8 @@ const getServerWebpack = (chain) => {
26
26
  chain.when(isDev, () => {
27
27
  chain.watch(true);
28
28
  });
29
- chain.plugin('define').use(webpack.DefinePlugin, [{
30
- __isBrowser__: false
29
+ chain.plugin('serverLimit').use(webpack.optimize.LimitChunkCountPlugin, [{
30
+ maxChunks: 1
31
31
  }]);
32
32
  chainServerConfig(chain); // 合并用户自定义配置
33
33
  return chain.toConfig();
@@ -1,4 +1,3 @@
1
- //@ts-nocheck
2
1
  import * as React from 'react';
3
2
  import * as ReactDOM from 'react-dom';
4
3
  import { BrowserRouter, Route, Switch } from 'react-router-dom';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssr-plugin-react",
3
- "version": "5.6.22",
3
+ "version": "5.6.26",
4
4
  "description": "plugin-react for ssr",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -53,10 +53,10 @@
53
53
  "postcss-safe-parser": "4.0.1",
54
54
  "react-dev-utils": "^11.0.4",
55
55
  "serialize-javascript": "^3.0.0",
56
- "ssr-client-utils": "^5.6.13",
57
- "ssr-hoc-react": "^5.6.19",
58
- "ssr-server-utils": "^5.6.17",
59
- "ssr-webpack": "^5.6.17",
56
+ "ssr-client-utils": "^5.6.26",
57
+ "ssr-hoc-react": "^5.6.24",
58
+ "ssr-server-utils": "^5.6.26",
59
+ "ssr-webpack": "^5.6.26",
60
60
  "terser-webpack-plugin": "^2.3.5",
61
61
  "url-loader": "1.1.1",
62
62
  "webpack-bundle-analyzer": "^3.6.1",
@@ -70,7 +70,7 @@
70
70
  "@types/react-router-dom": "^5.1.3",
71
71
  "@types/serialize-javascript": "^1.5.0",
72
72
  "@types/webpack": "^4.41.10",
73
- "ssr-types-react": "^5.6.19"
73
+ "ssr-types-react": "^5.6.24"
74
74
  },
75
- "gitHead": "22b10331bd9e7c4a1d35a42a40db2215eef8bea0"
75
+ "gitHead": "3824801e667480f6f0298d57b9240b629d3c0ff2"
76
76
  }
@@ -3,6 +3,7 @@ import { join } from 'path'
3
3
  import { Mode } from 'ssr-types'
4
4
  import { getFeDir, getCwd, loadConfig, getLocalNodeModules, setStyle, addImageChain } from 'ssr-server-utils'
5
5
  import * as WebpackChain from 'webpack-chain'
6
+ import * as webpack from 'webpack'
6
7
 
7
8
  const MiniCssExtractPlugin = require('mini-css-extract-plugin')
8
9
  const WebpackBar = require('webpackbar')
@@ -108,9 +109,6 @@ const getBaseConfig = (chain: WebpackChain, isServer: boolean) => {
108
109
 
109
110
  setStyle(chain, /\.css$/, {
110
111
  rule: 'css',
111
- modules: {
112
- auto: true
113
- },
114
112
  isServer,
115
113
  importLoaders: 1
116
114
  })
@@ -118,9 +116,6 @@ const getBaseConfig = (chain: WebpackChain, isServer: boolean) => {
118
116
  setStyle(chain, /\.less$/, {
119
117
  rule: 'less',
120
118
  loader: 'less-loader',
121
- modules: {
122
- auto: true
123
- },
124
119
  isServer,
125
120
  importLoaders: 2
126
121
  })
@@ -157,7 +152,9 @@ const getBaseConfig = (chain: WebpackChain, isServer: boolean) => {
157
152
  name: isServer ? 'server' : 'client',
158
153
  color: isServer ? '#f173ac' : '#45b97c'
159
154
  }))
160
-
155
+ chain.plugin('ssrDefine').use(webpack.DefinePlugin, [{
156
+ __isBrowser__: !isServer
157
+ }])
161
158
  chainBaseConfig(chain)
162
159
  return config
163
160
  }
@@ -1,7 +1,6 @@
1
1
  import { promises } from 'fs'
2
2
  import { resolve } from 'path'
3
3
  import { loadConfig, getCwd, cryptoAsyncChunkName, getOutputPublicPath } from 'ssr-server-utils'
4
- import * as webpack from 'webpack'
5
4
  import * as WebpackChain from 'webpack-chain'
6
5
  import { getBaseConfig } from './base'
7
6
 
@@ -84,10 +83,6 @@ const getClientWebpack = (chain: WebpackChain) => {
84
83
  }])
85
84
  })
86
85
 
87
- chain.plugin('define').use(webpack.DefinePlugin, [{
88
- __isBrowser__: true
89
- }])
90
-
91
86
  chain.plugin('moduleNotFound').use(ModuleNotFoundPlugin, [cwd])
92
87
 
93
88
  chain.plugin('manifest').use(loadModule('webpack-manifest-plugin'), [{
@@ -1,7 +1,7 @@
1
1
  import { join } from 'path'
2
- import * as webpack from 'webpack'
3
2
  import { loadConfig, getLocalNodeModules, nodeExternals } from 'ssr-server-utils'
4
3
  import * as WebpackChain from 'webpack-chain'
4
+ import * as webpack from 'webpack'
5
5
  import { getBaseConfig } from './base'
6
6
 
7
7
  const loadModule = require.resolve
@@ -33,8 +33,8 @@ const getServerWebpack = (chain: WebpackChain) => {
33
33
  chain.watch(true)
34
34
  })
35
35
 
36
- chain.plugin('define').use(webpack.DefinePlugin, [{
37
- __isBrowser__: false
36
+ chain.plugin('serverLimit').use(webpack.optimize.LimitChunkCountPlugin, [{
37
+ maxChunks: 1
38
38
  }])
39
39
 
40
40
  chainServerConfig(chain) // 合并用户自定义配置
@@ -1,4 +1,3 @@
1
- //@ts-nocheck
2
1
  import * as React from 'react'
3
2
  import * as ReactDOM from 'react-dom'
4
3
  import { BrowserRouter, Route, Switch } from 'react-router-dom'
@@ -24,22 +23,22 @@ const clientRender = async (): Promise<void> => {
24
23
  <BrowserRouter basename={BASE_NAME}>
25
24
  <AppContext>
26
25
  <Switch>
27
- <IApp>
28
- <Switch>
29
- {
30
- // 使用高阶组件wrapComponent使得csr首次进入页面以及csr/ssr切换路由时调用getInitialProps
31
- routes.map((item: ReactClientESMFeRouteItem) => {
32
- const { fetch, component, path } = item
33
- component.fetch = fetch
34
- component.layoutFetch = layoutFetch
35
- const WrappedComponent = wrapComponent(component)
36
- return (
37
- <Route exact={true} key={path} path={path} render={() => <WrappedComponent key={location.pathname}/>}/>
38
- )
39
- })
40
- }
26
+ <IApp>
27
+ <Switch>
28
+ {
29
+ // 使用高阶组件wrapComponent使得csr首次进入页面以及csr/ssr切换路由时调用getInitialProps
30
+ routes.map((item: ReactClientESMFeRouteItem) => {
31
+ const { fetch, component, path } = item
32
+ component.fetch = fetch
33
+ component.layoutFetch = layoutFetch
34
+ const WrappedComponent = wrapComponent(component)
35
+ return (
36
+ <Route exact={true} key={path} path={path} render={() => <WrappedComponent key={location.pathname}/>}/>
37
+ )
38
+ })
39
+ }
41
40
  </Switch>
42
- </IApp>
41
+ </IApp>
43
42
  </Switch>
44
43
  </AppContext>
45
44
  </BrowserRouter>