ssr-plugin-react 6.1.40 → 6.1.46
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 +54 -0
- package/README.md +1 -1
- package/cjs/config/base.js +6 -4
- package/cjs/config/client.js +2 -2
- package/cjs/config/server.js +1 -2
- package/cjs/tools/vite.js +7 -3
- package/esm/config/base.js +7 -5
- package/esm/config/client.js +3 -3
- package/esm/config/server.js +1 -2
- package/esm/tools/vite.js +7 -3
- package/package.json +8 -8
- package/src/config/base.ts +7 -5
- package/src/config/client.ts +3 -3
- package/src/config/server.ts +1 -3
- package/src/tools/vite.ts +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,60 @@
|
|
|
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
|
+
## [6.1.46](https://github.com/zhangyuang/ssr/compare/v6.1.45...v6.1.46) (2022-01-07)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package ssr-plugin-react
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [6.1.45](https://github.com/zhangyuang/ssr/compare/v6.1.44...v6.1.45) (2022-01-06)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package ssr-plugin-react
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [6.1.44](https://github.com/zhangyuang/ssr/compare/v6.1.42...v6.1.44) (2022-01-05)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* manualChunks ([663295c](https://github.com/zhangyuang/ssr/commit/663295c17693550301ac5a71ee78f68d3d11ecfa))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## [6.1.43](https://github.com/zhangyuang/ssr/compare/v6.1.42...v6.1.43) (2022-01-05)
|
|
34
|
+
|
|
35
|
+
**Note:** Version bump only for package ssr-plugin-react
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## [6.1.42](https://github.com/zhangyuang/ssr/compare/v6.1.41...v6.1.42) (2022-01-05)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Features
|
|
45
|
+
|
|
46
|
+
* support config.define ([c04f128](https://github.com/zhangyuang/ssr/commit/c04f12844e22300f57e17683cff0584e8f8ea123))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## [6.1.41](https://github.com/zhangyuang/ssr/compare/v6.1.40...v6.1.41) (2022-01-05)
|
|
53
|
+
|
|
54
|
+
**Note:** Version bump only for package ssr-plugin-react
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
6
60
|
## [6.1.40](https://github.com/zhangyuang/ssr/compare/v6.1.39...v6.1.40) (2022-01-04)
|
|
7
61
|
|
|
8
62
|
**Note:** Version bump only for package ssr-plugin-react
|
package/README.md
CHANGED
|
@@ -273,7 +273,7 @@ $ npm run start:vite # 以 vite 模式启动,等价于 npx ssr start --vite
|
|
|
273
273
|
|
|
274
274
|
<div style="display:flex">
|
|
275
275
|
<img src="https://res.wx.qq.com/op_res/7F1t4Z8yCHWilehbcFGjAj0yVn0URMiWBGVJa-TVu_eqw5IwUXA2kPYBnfX6YRHy0FVBB-yC6l0IEL02QTJkLg" width="300">
|
|
276
|
-
<img src="https://res.wx.qq.com/op_res/
|
|
276
|
+
<img src="https://res.wx.qq.com/op_res/7SpflSUP3RJ5InL7FkN0-9JeTj18T_lvqJXXHLNNpY_owTyqtgVH8qMqjk4w7S6YeDWZmUP-N_4vLLAUCdySTA" width="300">
|
|
277
277
|
</div>
|
|
278
278
|
|
|
279
279
|
## 前端开发手册
|
package/cjs/config/base.js
CHANGED
|
@@ -4,9 +4,9 @@ exports.getBaseConfig = void 0;
|
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const ssr_server_utils_1 = require("ssr-server-utils");
|
|
6
6
|
const webpack = require("webpack");
|
|
7
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
7
|
+
const MiniCssExtractPlugin = require((0, ssr_server_utils_1.loadModuleFromFramework)('mini-css-extract-plugin'));
|
|
8
8
|
const WebpackBar = require('webpackbar');
|
|
9
|
-
const loadModule =
|
|
9
|
+
const loadModule = ssr_server_utils_1.loadModuleFromFramework;
|
|
10
10
|
const addBabelLoader = (chain, envOptions) => {
|
|
11
11
|
chain.use('babel-loader')
|
|
12
12
|
.loader(loadModule('babel-loader'))
|
|
@@ -43,7 +43,7 @@ const addBabelLoader = (chain, envOptions) => {
|
|
|
43
43
|
};
|
|
44
44
|
const getBaseConfig = (chain, isServer) => {
|
|
45
45
|
const config = (0, ssr_server_utils_1.loadConfig)();
|
|
46
|
-
const { moduleFileExtensions, useHash, isDev, chainBaseConfig, corejsOptions, babelExtraModule, alias } = config;
|
|
46
|
+
const { moduleFileExtensions, useHash, isDev, chainBaseConfig, corejsOptions, babelExtraModule, alias, define } = config;
|
|
47
47
|
const mode = process.env.NODE_ENV;
|
|
48
48
|
const envOptions = {
|
|
49
49
|
modules: false,
|
|
@@ -119,7 +119,9 @@ const getBaseConfig = (chain, isServer) => {
|
|
|
119
119
|
color: isServer ? '#f173ac' : '#45b97c'
|
|
120
120
|
}));
|
|
121
121
|
chain.plugin('ssrDefine').use(webpack.DefinePlugin, [{
|
|
122
|
-
__isBrowser__: !isServer
|
|
122
|
+
__isBrowser__: !isServer,
|
|
123
|
+
...(isServer ? define === null || define === void 0 ? void 0 : define.server : define === null || define === void 0 ? void 0 : define.client),
|
|
124
|
+
...define === null || define === void 0 ? void 0 : define.base
|
|
123
125
|
}]);
|
|
124
126
|
chainBaseConfig(chain);
|
|
125
127
|
return config;
|
package/cjs/config/client.js
CHANGED
|
@@ -9,7 +9,7 @@ const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
|
|
|
9
9
|
const safePostCssParser = require('postcss-safe-parser');
|
|
10
10
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
11
11
|
const generateAnalysis = Boolean(process.env.GENERATE_ANALYSIS);
|
|
12
|
-
const loadModule =
|
|
12
|
+
const loadModule = ssr_server_utils_1.loadModuleFromFramework;
|
|
13
13
|
let asyncChunkMap = {};
|
|
14
14
|
const getClientWebpack = (chain) => {
|
|
15
15
|
const { isDev, chunkName, getOutput, cwd, useHash, chainClientConfig } = (0, ssr_server_utils_1.loadConfig)();
|
|
@@ -18,7 +18,7 @@ const getClientWebpack = (chain) => {
|
|
|
18
18
|
(0, base_1.getBaseConfig)(chain, false);
|
|
19
19
|
chain.devtool(isDev ? 'cheap-module-source-map' : (shouldUseSourceMap ? 'source-map' : false));
|
|
20
20
|
chain.entry(chunkName)
|
|
21
|
-
.add(
|
|
21
|
+
.add(require.resolve('../entry/client-entry'))
|
|
22
22
|
.end()
|
|
23
23
|
.output
|
|
24
24
|
.path(getOutput().clientOutPut)
|
package/cjs/config/server.js
CHANGED
|
@@ -5,7 +5,6 @@ const path_1 = require("path");
|
|
|
5
5
|
const ssr_server_utils_1 = require("ssr-server-utils");
|
|
6
6
|
const webpack = require("webpack");
|
|
7
7
|
const base_1 = require("./base");
|
|
8
|
-
const loadModule = require.resolve;
|
|
9
8
|
const getServerWebpack = (chain) => {
|
|
10
9
|
const config = (0, ssr_server_utils_1.loadConfig)();
|
|
11
10
|
const { isDev, cwd, getOutput, chainServerConfig, whiteList, chunkName } = config;
|
|
@@ -13,7 +12,7 @@ const getServerWebpack = (chain) => {
|
|
|
13
12
|
chain.devtool(isDev ? 'inline-source-map' : false);
|
|
14
13
|
chain.target('node');
|
|
15
14
|
chain.entry(chunkName)
|
|
16
|
-
.add(
|
|
15
|
+
.add(require.resolve('../entry/server-entry'))
|
|
17
16
|
.end()
|
|
18
17
|
.output
|
|
19
18
|
.path(getOutput().serverOutPut)
|
package/cjs/tools/vite.js
CHANGED
|
@@ -6,7 +6,7 @@ const ssr_server_utils_1 = require("ssr-server-utils");
|
|
|
6
6
|
const plugin_react_1 = require("@vitejs/plugin-react");
|
|
7
7
|
const vite_plugin_style_import_1 = require("vite-plugin-style-import");
|
|
8
8
|
const build = require('vite').build;
|
|
9
|
-
const { getOutput, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev } = (0, ssr_server_utils_1.loadConfig)();
|
|
9
|
+
const { getOutput, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev, define } = (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/],
|
|
@@ -47,7 +47,9 @@ const serverConfig = {
|
|
|
47
47
|
},
|
|
48
48
|
define: {
|
|
49
49
|
__isBrowser__: false,
|
|
50
|
-
...(_h = (_g = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _g === void 0 ? void 0 : _g.server) === null || _h === void 0 ? void 0 : _h.define
|
|
50
|
+
...(_h = (_g = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _g === void 0 ? void 0 : _g.server) === null || _h === void 0 ? void 0 : _h.define,
|
|
51
|
+
...define === null || define === void 0 ? void 0 : define.server,
|
|
52
|
+
...define === null || define === void 0 ? void 0 : define.base
|
|
51
53
|
}
|
|
52
54
|
};
|
|
53
55
|
exports.serverConfig = serverConfig;
|
|
@@ -76,7 +78,9 @@ const clientConfig = {
|
|
|
76
78
|
},
|
|
77
79
|
define: {
|
|
78
80
|
__isBrowser__: true,
|
|
79
|
-
...(_r = (_q = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _q === void 0 ? void 0 : _q.client) === null || _r === void 0 ? void 0 : _r.define
|
|
81
|
+
...(_r = (_q = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _q === void 0 ? void 0 : _q.client) === null || _r === void 0 ? void 0 : _r.define,
|
|
82
|
+
...define === null || define === void 0 ? void 0 : define.client,
|
|
83
|
+
...define === null || define === void 0 ? void 0 : define.base
|
|
80
84
|
}
|
|
81
85
|
};
|
|
82
86
|
exports.clientConfig = clientConfig;
|
package/esm/config/base.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
|
-
import { getCwd, loadConfig, getLocalNodeModules, setStyle, addImageChain } from 'ssr-server-utils';
|
|
2
|
+
import { getCwd, loadConfig, getLocalNodeModules, setStyle, addImageChain, loadModuleFromFramework } from 'ssr-server-utils';
|
|
3
3
|
import * as webpack from 'webpack';
|
|
4
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
4
|
+
const MiniCssExtractPlugin = require(loadModuleFromFramework('mini-css-extract-plugin'));
|
|
5
5
|
const WebpackBar = require('webpackbar');
|
|
6
|
-
const loadModule =
|
|
6
|
+
const loadModule = loadModuleFromFramework;
|
|
7
7
|
const addBabelLoader = (chain, envOptions) => {
|
|
8
8
|
chain.use('babel-loader')
|
|
9
9
|
.loader(loadModule('babel-loader'))
|
|
@@ -40,7 +40,7 @@ const addBabelLoader = (chain, envOptions) => {
|
|
|
40
40
|
};
|
|
41
41
|
const getBaseConfig = (chain, isServer) => {
|
|
42
42
|
const config = loadConfig();
|
|
43
|
-
const { moduleFileExtensions, useHash, isDev, chainBaseConfig, corejsOptions, babelExtraModule, alias } = config;
|
|
43
|
+
const { moduleFileExtensions, useHash, isDev, chainBaseConfig, corejsOptions, babelExtraModule, alias, define } = config;
|
|
44
44
|
const mode = process.env.NODE_ENV;
|
|
45
45
|
const envOptions = {
|
|
46
46
|
modules: false,
|
|
@@ -116,7 +116,9 @@ const getBaseConfig = (chain, isServer) => {
|
|
|
116
116
|
color: isServer ? '#f173ac' : '#45b97c'
|
|
117
117
|
}));
|
|
118
118
|
chain.plugin('ssrDefine').use(webpack.DefinePlugin, [{
|
|
119
|
-
__isBrowser__: !isServer
|
|
119
|
+
__isBrowser__: !isServer,
|
|
120
|
+
...(isServer ? define === null || define === void 0 ? void 0 : define.server : define === null || define === void 0 ? void 0 : define.client),
|
|
121
|
+
...define === null || define === void 0 ? void 0 : define.base
|
|
120
122
|
}]);
|
|
121
123
|
chainBaseConfig(chain);
|
|
122
124
|
return config;
|
package/esm/config/client.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { promises } from 'fs';
|
|
2
2
|
import { resolve } from 'path';
|
|
3
|
-
import { loadConfig, getCwd, cryptoAsyncChunkName, getOutputPublicPath } from 'ssr-server-utils';
|
|
3
|
+
import { loadConfig, getCwd, cryptoAsyncChunkName, getOutputPublicPath, loadModuleFromFramework } from 'ssr-server-utils';
|
|
4
4
|
import { getBaseConfig } from './base';
|
|
5
5
|
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
|
|
6
6
|
const safePostCssParser = require('postcss-safe-parser');
|
|
7
7
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
8
8
|
const generateAnalysis = Boolean(process.env.GENERATE_ANALYSIS);
|
|
9
|
-
const loadModule =
|
|
9
|
+
const loadModule = loadModuleFromFramework;
|
|
10
10
|
let asyncChunkMap = {};
|
|
11
11
|
const getClientWebpack = (chain) => {
|
|
12
12
|
const { isDev, chunkName, getOutput, cwd, useHash, chainClientConfig } = loadConfig();
|
|
@@ -15,7 +15,7 @@ const getClientWebpack = (chain) => {
|
|
|
15
15
|
getBaseConfig(chain, false);
|
|
16
16
|
chain.devtool(isDev ? 'cheap-module-source-map' : (shouldUseSourceMap ? 'source-map' : false));
|
|
17
17
|
chain.entry(chunkName)
|
|
18
|
-
.add(
|
|
18
|
+
.add(require.resolve('../entry/client-entry'))
|
|
19
19
|
.end()
|
|
20
20
|
.output
|
|
21
21
|
.path(getOutput().clientOutPut)
|
package/esm/config/server.js
CHANGED
|
@@ -2,7 +2,6 @@ import { join } from 'path';
|
|
|
2
2
|
import { loadConfig, getLocalNodeModules, nodeExternals } from 'ssr-server-utils';
|
|
3
3
|
import * as webpack from 'webpack';
|
|
4
4
|
import { getBaseConfig } from './base';
|
|
5
|
-
const loadModule = require.resolve;
|
|
6
5
|
const getServerWebpack = (chain) => {
|
|
7
6
|
const config = loadConfig();
|
|
8
7
|
const { isDev, cwd, getOutput, chainServerConfig, whiteList, chunkName } = config;
|
|
@@ -10,7 +9,7 @@ const getServerWebpack = (chain) => {
|
|
|
10
9
|
chain.devtool(isDev ? 'inline-source-map' : false);
|
|
11
10
|
chain.target('node');
|
|
12
11
|
chain.entry(chunkName)
|
|
13
|
-
.add(
|
|
12
|
+
.add(require.resolve('../entry/server-entry'))
|
|
14
13
|
.end()
|
|
15
14
|
.output
|
|
16
15
|
.path(getOutput().serverOutPut)
|
package/esm/tools/vite.js
CHANGED
|
@@ -3,7 +3,7 @@ import { loadConfig, chunkNamePlugin, rollupOutputOptions, manifestPlugin, commo
|
|
|
3
3
|
import react from '@vitejs/plugin-react';
|
|
4
4
|
import styleImport, { AndDesignVueResolve, VantResolve, ElementPlusResolve, NutuiResolve, AntdResolve } from 'vite-plugin-style-import';
|
|
5
5
|
const build = require('vite').build;
|
|
6
|
-
const { getOutput, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev } = loadConfig();
|
|
6
|
+
const { getOutput, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev, define } = loadConfig();
|
|
7
7
|
const { clientOutPut, serverOutPut } = getOutput();
|
|
8
8
|
const styleImportConfig = {
|
|
9
9
|
include: ['**/*.vue', '**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx', /chunkName/],
|
|
@@ -44,7 +44,9 @@ const serverConfig = {
|
|
|
44
44
|
},
|
|
45
45
|
define: {
|
|
46
46
|
__isBrowser__: false,
|
|
47
|
-
...(_h = (_g = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _g === void 0 ? void 0 : _g.server) === null || _h === void 0 ? void 0 : _h.define
|
|
47
|
+
...(_h = (_g = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _g === void 0 ? void 0 : _g.server) === null || _h === void 0 ? void 0 : _h.define,
|
|
48
|
+
...define === null || define === void 0 ? void 0 : define.server,
|
|
49
|
+
...define === null || define === void 0 ? void 0 : define.base
|
|
48
50
|
}
|
|
49
51
|
};
|
|
50
52
|
const clientConfig = {
|
|
@@ -72,7 +74,9 @@ const clientConfig = {
|
|
|
72
74
|
},
|
|
73
75
|
define: {
|
|
74
76
|
__isBrowser__: true,
|
|
75
|
-
...(_r = (_q = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _q === void 0 ? void 0 : _q.client) === null || _r === void 0 ? void 0 : _r.define
|
|
77
|
+
...(_r = (_q = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _q === void 0 ? void 0 : _q.client) === null || _r === void 0 ? void 0 : _r.define,
|
|
78
|
+
...define === null || define === void 0 ? void 0 : define.client,
|
|
79
|
+
...define === null || define === void 0 ? void 0 : define.base
|
|
76
80
|
}
|
|
77
81
|
};
|
|
78
82
|
const viteStart = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssr-plugin-react",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.46",
|
|
4
4
|
"description": "plugin-react for ssr",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"babel-loader": "8.0.4",
|
|
39
39
|
"babel-plugin-import": "^1.13.0",
|
|
40
40
|
"babel-preset-react-app": "^9.0.2",
|
|
41
|
-
"concurrently": "^5.1.0",
|
|
42
41
|
"core-js": "^3.6.4",
|
|
43
42
|
"css-hot-loader": "^1.4.4",
|
|
44
43
|
"css-loader": "^5.2.7",
|
|
@@ -56,10 +55,10 @@
|
|
|
56
55
|
"postcss-safe-parser": "4.0.1",
|
|
57
56
|
"react-dev-utils": "^11.0.4",
|
|
58
57
|
"serialize-javascript": "^6.0.0",
|
|
59
|
-
"ssr-client-utils": "^6.1.
|
|
60
|
-
"ssr-hoc-react": "^6.1.
|
|
61
|
-
"ssr-server-utils": "^6.1.
|
|
62
|
-
"ssr-webpack": "^6.1.
|
|
58
|
+
"ssr-client-utils": "^6.1.46",
|
|
59
|
+
"ssr-hoc-react": "^6.1.46",
|
|
60
|
+
"ssr-server-utils": "^6.1.46",
|
|
61
|
+
"ssr-webpack": "^6.1.46",
|
|
63
62
|
"terser-webpack-plugin": "^2.3.5",
|
|
64
63
|
"url-loader": "^4.1.1",
|
|
65
64
|
"vite": "^2.7.0",
|
|
@@ -74,7 +73,8 @@
|
|
|
74
73
|
"@types/react-dom": "^17.0.0",
|
|
75
74
|
"@types/react-router-dom": "^5.1.3",
|
|
76
75
|
"@types/webpack": "^4.41.10",
|
|
77
|
-
"
|
|
76
|
+
"concurrently": "^5.1.0",
|
|
77
|
+
"ssr-types-react": "^6.1.46"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "f79b4f0962989f1bf8eeddf0e05f79708e97fbf8"
|
|
80
80
|
}
|
package/src/config/base.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
import { join } from 'path'
|
|
3
3
|
import { Mode } from 'ssr-types'
|
|
4
|
-
import { getCwd, loadConfig, getLocalNodeModules, setStyle, addImageChain } from 'ssr-server-utils'
|
|
4
|
+
import { getCwd, loadConfig, getLocalNodeModules, setStyle, addImageChain, loadModuleFromFramework } from 'ssr-server-utils'
|
|
5
5
|
import * as WebpackChain from 'webpack-chain'
|
|
6
6
|
import * as webpack from 'webpack'
|
|
7
7
|
|
|
8
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
8
|
+
const MiniCssExtractPlugin = require(loadModuleFromFramework('mini-css-extract-plugin'))
|
|
9
9
|
const WebpackBar = require('webpackbar')
|
|
10
|
-
const loadModule =
|
|
10
|
+
const loadModule = loadModuleFromFramework
|
|
11
11
|
|
|
12
12
|
const addBabelLoader = (chain: WebpackChain.Rule<WebpackChain.Module>, envOptions: any) => {
|
|
13
13
|
chain.use('babel-loader')
|
|
@@ -45,7 +45,7 @@ const addBabelLoader = (chain: WebpackChain.Rule<WebpackChain.Module>, envOption
|
|
|
45
45
|
}
|
|
46
46
|
const getBaseConfig = (chain: WebpackChain, isServer: boolean) => {
|
|
47
47
|
const config = loadConfig()
|
|
48
|
-
const { moduleFileExtensions, useHash, isDev, chainBaseConfig, corejsOptions, babelExtraModule, alias } = config
|
|
48
|
+
const { moduleFileExtensions, useHash, isDev, chainBaseConfig, corejsOptions, babelExtraModule, alias, define } = config
|
|
49
49
|
const mode = process.env.NODE_ENV as Mode
|
|
50
50
|
const envOptions = {
|
|
51
51
|
modules: false,
|
|
@@ -132,7 +132,9 @@ const getBaseConfig = (chain: WebpackChain, isServer: boolean) => {
|
|
|
132
132
|
color: isServer ? '#f173ac' : '#45b97c'
|
|
133
133
|
}))
|
|
134
134
|
chain.plugin('ssrDefine').use(webpack.DefinePlugin, [{
|
|
135
|
-
__isBrowser__: !isServer
|
|
135
|
+
__isBrowser__: !isServer,
|
|
136
|
+
...(isServer ? define?.server : define?.client),
|
|
137
|
+
...define?.base
|
|
136
138
|
}])
|
|
137
139
|
chainBaseConfig(chain)
|
|
138
140
|
return config
|
package/src/config/client.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { promises } from 'fs'
|
|
2
2
|
import { resolve } from 'path'
|
|
3
|
-
import { loadConfig, getCwd, cryptoAsyncChunkName, getOutputPublicPath } from 'ssr-server-utils'
|
|
3
|
+
import { loadConfig, getCwd, cryptoAsyncChunkName, getOutputPublicPath, loadModuleFromFramework } from 'ssr-server-utils'
|
|
4
4
|
import * as WebpackChain from 'webpack-chain'
|
|
5
5
|
import { getBaseConfig } from './base'
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin')
|
|
|
8
8
|
const safePostCssParser = require('postcss-safe-parser')
|
|
9
9
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
|
|
10
10
|
const generateAnalysis = Boolean(process.env.GENERATE_ANALYSIS)
|
|
11
|
-
const loadModule =
|
|
11
|
+
const loadModule = loadModuleFromFramework
|
|
12
12
|
let asyncChunkMap: Record<string, string> = {}
|
|
13
13
|
|
|
14
14
|
const getClientWebpack = (chain: WebpackChain) => {
|
|
@@ -18,7 +18,7 @@ const getClientWebpack = (chain: WebpackChain) => {
|
|
|
18
18
|
getBaseConfig(chain, false)
|
|
19
19
|
chain.devtool(isDev ? 'cheap-module-source-map' : (shouldUseSourceMap ? 'source-map' : false))
|
|
20
20
|
chain.entry(chunkName)
|
|
21
|
-
.add(
|
|
21
|
+
.add(require.resolve('../entry/client-entry'))
|
|
22
22
|
.end()
|
|
23
23
|
.output
|
|
24
24
|
.path(getOutput().clientOutPut)
|
package/src/config/server.ts
CHANGED
|
@@ -4,8 +4,6 @@ import * as WebpackChain from 'webpack-chain'
|
|
|
4
4
|
import * as webpack from 'webpack'
|
|
5
5
|
import { getBaseConfig } from './base'
|
|
6
6
|
|
|
7
|
-
const loadModule = require.resolve
|
|
8
|
-
|
|
9
7
|
const getServerWebpack = (chain: WebpackChain) => {
|
|
10
8
|
const config = loadConfig()
|
|
11
9
|
const { isDev, cwd, getOutput, chainServerConfig, whiteList, chunkName } = config
|
|
@@ -13,7 +11,7 @@ const getServerWebpack = (chain: WebpackChain) => {
|
|
|
13
11
|
chain.devtool(isDev ? 'inline-source-map' : false)
|
|
14
12
|
chain.target('node')
|
|
15
13
|
chain.entry(chunkName)
|
|
16
|
-
.add(
|
|
14
|
+
.add(require.resolve('../entry/server-entry'))
|
|
17
15
|
.end()
|
|
18
16
|
.output
|
|
19
17
|
.path(getOutput().serverOutPut)
|
package/src/tools/vite.ts
CHANGED
|
@@ -10,7 +10,7 @@ import styleImport, {
|
|
|
10
10
|
} from 'vite-plugin-style-import'
|
|
11
11
|
|
|
12
12
|
const build: typeof BuildType = require('vite').build
|
|
13
|
-
const { getOutput, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev } = loadConfig()
|
|
13
|
+
const { getOutput, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev, define } = loadConfig()
|
|
14
14
|
|
|
15
15
|
const { clientOutPut, serverOutPut } = getOutput()
|
|
16
16
|
const styleImportConfig = {
|
|
@@ -52,7 +52,9 @@ const serverConfig: UserConfig = {
|
|
|
52
52
|
},
|
|
53
53
|
define: {
|
|
54
54
|
__isBrowser__: false,
|
|
55
|
-
...viteConfig?.()?.server?.define
|
|
55
|
+
...viteConfig?.()?.server?.define,
|
|
56
|
+
...define?.server,
|
|
57
|
+
...define?.base
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -81,7 +83,9 @@ const clientConfig: UserConfig = {
|
|
|
81
83
|
},
|
|
82
84
|
define: {
|
|
83
85
|
__isBrowser__: true,
|
|
84
|
-
...viteConfig?.()?.client?.define
|
|
86
|
+
...viteConfig?.()?.client?.define,
|
|
87
|
+
...define?.client,
|
|
88
|
+
...define?.base
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
const viteStart = async () => {
|