ssr-plugin-react 6.2.68 → 6.2.70
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/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +35 -0
- package/README.md +9 -9
- package/cjs/entry/client-entry.d.ts.map +1 -1
- package/cjs/entry/client-entry.js +9 -5
- package/cjs/entry/client-entry.js.map +1 -1
- package/cjs/entry/server-entry.d.ts.map +1 -1
- package/cjs/entry/server-entry.js +5 -3
- package/cjs/entry/server-entry.js.map +1 -1
- package/cjs/tools/vite.d.ts.map +1 -1
- package/cjs/tools/vite.js +21 -16
- package/cjs/tools/vite.js.map +1 -1
- package/esm/entry/client-entry.d.ts.map +1 -1
- package/esm/entry/client-entry.js +10 -6
- package/esm/entry/client-entry.js.map +1 -1
- package/esm/entry/server-entry.d.ts.map +1 -1
- package/esm/entry/server-entry.js +6 -4
- package/esm/entry/server-entry.js.map +1 -1
- package/esm/tools/vite.d.ts.map +1 -1
- package/esm/tools/vite.js +22 -17
- package/esm/tools/vite.js.map +1 -1
- package/package.json +2 -1
- package/src/config/base.ts +0 -65
- package/src/config/client.ts +0 -66
- package/src/config/index.ts +0 -2
- package/src/config/server.ts +0 -56
- package/src/entry/client-entry.tsx +0 -53
- package/src/entry/context.tsx +0 -40
- package/src/entry/create-context.ts +0 -19
- package/src/entry/create-router.ts +0 -10
- package/src/entry/server-entry.tsx +0 -104
- package/src/index.ts +0 -49
- package/src/tools/vite.ts +0 -142
- package/src/tools/webpack.ts +0 -20
package/esm/tools/vite.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26;
|
|
1
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35;
|
|
2
2
|
import { build } from 'vite';
|
|
3
|
-
import { loadConfig, chunkNamePlugin, rollupOutputOptions, manifestPlugin, commonConfig, asyncOptimizeChunkPlugin, getOutputPublicPath } from 'ssr-common-utils';
|
|
3
|
+
import { loadConfig, chunkNamePlugin, rollupOutputOptions, manifestPlugin, commonConfig, asyncOptimizeChunkPlugin, getOutputPublicPath, judgeAntd } from 'ssr-common-utils';
|
|
4
4
|
import react from '@vitejs/plugin-react';
|
|
5
5
|
import { createStyleImportPlugin, AndDesignVueResolve, VantResolve, ElementPlusResolve, NutuiResolve, AntdResolve } from 'ssr-vite-plugin-style-import';
|
|
6
6
|
const { getOutput, reactServerEntry, reactClientEntry, viteConfig, supportOptinalChaining, isDev, define, babelOptions, optimize } = loadConfig();
|
|
7
7
|
const { clientOutPut, serverOutPut } = getOutput();
|
|
8
|
+
const isAntd5 = judgeAntd() === 5;
|
|
9
|
+
const extraInclude = [].concat(isAntd5 ? ['react-is'] : []);
|
|
8
10
|
const styleImportConfig = {
|
|
9
11
|
include: ['**/*.vue', '**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx', /chunkName/],
|
|
10
12
|
resolves: [
|
|
@@ -44,17 +46,20 @@ const serverConfig = {
|
|
|
44
46
|
logOverride: { 'this-is-undefined-in-esm': 'silent' }
|
|
45
47
|
},
|
|
46
48
|
optimizeDeps: {
|
|
49
|
+
...(_r = (_q = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().server) === null || _q === void 0 ? void 0 : _q.otherConfig) === null || _r === void 0 ? void 0 : _r.optimizeDeps,
|
|
50
|
+
include: extraInclude.concat(...(_v = (_u = (_t = (_s = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().server) === null || _s === void 0 ? void 0 : _s.otherConfig) === null || _t === void 0 ? void 0 : _t.optimizeDeps) === null || _u === void 0 ? void 0 : _u.include) !== null && _v !== void 0 ? _v : []),
|
|
47
51
|
esbuildOptions: {
|
|
52
|
+
...(_y = (_x = (_w = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().server) === null || _w === void 0 ? void 0 : _w.otherConfig) === null || _x === void 0 ? void 0 : _x.optimizeDeps) === null || _y === void 0 ? void 0 : _y.esbuildOptions,
|
|
48
53
|
// @ts-expect-error
|
|
49
54
|
bundle: isDev
|
|
50
55
|
}
|
|
51
56
|
},
|
|
52
57
|
build: {
|
|
53
|
-
...(
|
|
58
|
+
...(_0 = (_z = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().server) === null || _z === void 0 ? void 0 : _z.otherConfig) === null || _0 === void 0 ? void 0 : _0.build,
|
|
54
59
|
ssr: reactServerEntry,
|
|
55
60
|
outDir: serverOutPut,
|
|
56
61
|
rollupOptions: {
|
|
57
|
-
...(
|
|
62
|
+
...(_3 = (_2 = (_1 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().server) === null || _1 === void 0 ? void 0 : _1.otherConfig) === null || _2 === void 0 ? void 0 : _2.build) === null || _3 === void 0 ? void 0 : _3.rollupOptions,
|
|
58
63
|
input: isDev ? reactClientEntry : reactServerEntry,
|
|
59
64
|
output: {
|
|
60
65
|
entryFileNames: 'Page.server.js',
|
|
@@ -63,7 +68,7 @@ const serverConfig = {
|
|
|
63
68
|
}
|
|
64
69
|
},
|
|
65
70
|
define: {
|
|
66
|
-
...(
|
|
71
|
+
...(_5 = (_4 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().server) === null || _4 === void 0 ? void 0 : _4.otherConfig) === null || _5 === void 0 ? void 0 : _5.define,
|
|
67
72
|
__isBrowser__: false,
|
|
68
73
|
...define === null || define === void 0 ? void 0 : define.base,
|
|
69
74
|
...define === null || define === void 0 ? void 0 : define.server
|
|
@@ -71,43 +76,43 @@ const serverConfig = {
|
|
|
71
76
|
};
|
|
72
77
|
const clientPlugins = [
|
|
73
78
|
react({
|
|
74
|
-
...(
|
|
79
|
+
...(_7 = (_6 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _6 === void 0 ? void 0 : _6.client) === null || _7 === void 0 ? void 0 : _7.defaultPluginOptions,
|
|
75
80
|
jsxRuntime: 'automatic',
|
|
76
81
|
...babelOptions
|
|
77
82
|
}),
|
|
78
|
-
(
|
|
79
|
-
(
|
|
83
|
+
(_9 = (_8 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _8 === void 0 ? void 0 : _8.common) === null || _9 === void 0 ? void 0 : _9.extraPlugin,
|
|
84
|
+
(_11 = (_10 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _10 === void 0 ? void 0 : _10.client) === null || _11 === void 0 ? void 0 : _11.extraPlugin,
|
|
80
85
|
createStyleImportPlugin(styleImportConfig)
|
|
81
86
|
].filter(Boolean);
|
|
82
87
|
const clientConfig = {
|
|
83
88
|
...commonConfig(),
|
|
84
|
-
...(
|
|
89
|
+
...(_12 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().client) === null || _12 === void 0 ? void 0 : _12.otherConfig,
|
|
85
90
|
base: isDev ? '/' : getOutputPublicPath(),
|
|
86
91
|
esbuild: {
|
|
87
|
-
...(
|
|
92
|
+
...(_14 = (_13 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().client) === null || _13 === void 0 ? void 0 : _13.otherConfig) === null || _14 === void 0 ? void 0 : _14.esbuild,
|
|
88
93
|
keepNames: true,
|
|
89
94
|
logOverride: { 'this-is-undefined-in-esm': 'silent' }
|
|
90
95
|
},
|
|
91
96
|
optimizeDeps: {
|
|
92
|
-
...(
|
|
93
|
-
include: ['react-router'].concat(...(
|
|
94
|
-
exclude: ['ssr-hoc-react'].concat(...(
|
|
97
|
+
...(_16 = (_15 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().client) === null || _15 === void 0 ? void 0 : _15.otherConfig) === null || _16 === void 0 ? void 0 : _16.optimizeDeps,
|
|
98
|
+
include: ['react-router', ...extraInclude].concat(...(_20 = (_19 = (_18 = (_17 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().client) === null || _17 === void 0 ? void 0 : _17.otherConfig) === null || _18 === void 0 ? void 0 : _18.optimizeDeps) === null || _19 === void 0 ? void 0 : _19.include) !== null && _20 !== void 0 ? _20 : []),
|
|
99
|
+
exclude: ['ssr-hoc-react'].concat(...(_24 = (_23 = (_22 = (_21 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().client) === null || _21 === void 0 ? void 0 : _21.otherConfig) === null || _22 === void 0 ? void 0 : _22.optimizeDeps) === null || _23 === void 0 ? void 0 : _23.exclude) !== null && _24 !== void 0 ? _24 : [])
|
|
95
100
|
},
|
|
96
|
-
plugins: (
|
|
101
|
+
plugins: (_28 = (_27 = (_26 = (_25 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _25 === void 0 ? void 0 : _25.client) === null || _26 === void 0 ? void 0 : _26.processPlugin) === null || _27 === void 0 ? void 0 : _27.call(_26, clientPlugins)) !== null && _28 !== void 0 ? _28 : clientPlugins,
|
|
97
102
|
build: {
|
|
98
|
-
...(
|
|
103
|
+
...(_30 = (_29 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().client) === null || _29 === void 0 ? void 0 : _29.otherConfig) === null || _30 === void 0 ? void 0 : _30.build,
|
|
99
104
|
...(optimize ? { write: false } : {}),
|
|
100
105
|
ssrManifest: true,
|
|
101
106
|
outDir: clientOutPut,
|
|
102
107
|
rollupOptions: {
|
|
103
|
-
...(
|
|
108
|
+
...(_33 = (_32 = (_31 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().client) === null || _31 === void 0 ? void 0 : _31.otherConfig) === null || _32 === void 0 ? void 0 : _32.build) === null || _33 === void 0 ? void 0 : _33.rollupOptions,
|
|
104
109
|
input: reactClientEntry,
|
|
105
110
|
output: rollupOutputOptions(),
|
|
106
111
|
plugins: [chunkNamePlugin(), asyncOptimizeChunkPlugin(), manifestPlugin()]
|
|
107
112
|
}
|
|
108
113
|
},
|
|
109
114
|
define: {
|
|
110
|
-
...(
|
|
115
|
+
...(_35 = (_34 = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig().client) === null || _34 === void 0 ? void 0 : _34.otherConfig) === null || _35 === void 0 ? void 0 : _35.define,
|
|
111
116
|
__isBrowser__: true,
|
|
112
117
|
...define === null || define === void 0 ? void 0 : define.base,
|
|
113
118
|
...define === null || define === void 0 ? void 0 : define.client
|
package/esm/tools/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../src/tools/vite.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,MAAM,CAAA;AACxC,OAAO,EACL,UAAU,EAAE,eAAe,EAAE,mBAAmB,EAAE,cAAc,EAAE,YAAY,EAC9E,wBAAwB,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../src/tools/vite.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,MAAM,CAAA;AACxC,OAAO,EACL,UAAU,EAAE,eAAe,EAAE,mBAAmB,EAAE,cAAc,EAAE,YAAY,EAC9E,wBAAwB,EAAE,mBAAmB,EAAE,SAAS,EACzD,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,MAAM,sBAAsB,CAAA;AACxC,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,WAAW,EAAE,kBAAkB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AACvJ,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,EAAE,YA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AAU,uBAAV,UAAU,GAAK,MAAM,4CAAE,WAAW,4CAAE,MAAM;QAC7C,aAAa,EAAE,IAAI;QACnB,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI;QACf,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM;KAClB;CACF,CAAA;AACD,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;IAC3B,EAAE;AACJ,CAAC,CAAA;AACD,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;IAC3B,MAAM,KAAK,CAAC,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;IACpD,MAAM,KAAK,CAAC,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;AACtD,CAAC,CAAA;AAED,MAAM,eAAe,GAAG,KAAK,IAAI,EAAE;IACjC,MAAM,KAAK,CAAC,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;AACtE,CAAC,CAAA;AACD,MAAM,eAAe,GAAG,KAAK,IAAI,EAAE;IACjC,MAAM,KAAK,CAAC,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;AACtD,CAAC,CAAA;AAED,OAAO,EACL,SAAS,EACT,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,eAAe,EAChB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssr-plugin-react",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.70",
|
|
4
4
|
"description": "plugin-react for ssr",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"ssr-webpack4": "^4.46.2",
|
|
74
74
|
"terser-webpack-plugin": "^2.3.5",
|
|
75
75
|
"url-loader": "^4.1.1",
|
|
76
|
+
"valtio": "^1.11.2",
|
|
76
77
|
"vite": "^2.9.15",
|
|
77
78
|
"webpack-bundle-analyzer": "^3.6.1",
|
|
78
79
|
"webpack-chain": "^6.4.0",
|
package/src/config/base.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { join } from 'path'
|
|
3
|
-
import { Mode } from 'ssr-types'
|
|
4
|
-
import { getCwd, loadConfig, setStyle, loadModuleFromFramework, getBuildConfig, addCommonChain } from 'ssr-common-utils'
|
|
5
|
-
import * as WebpackChain from 'webpack-chain'
|
|
6
|
-
import * as webpack from 'ssr-webpack4'
|
|
7
|
-
|
|
8
|
-
const MiniCssExtractPlugin = require(loadModuleFromFramework('ssr-mini-css-extract-plugin'))
|
|
9
|
-
const WebpackBar = require('webpackbar')
|
|
10
|
-
|
|
11
|
-
const getBaseConfig = (chain: WebpackChain, isServer: boolean) => {
|
|
12
|
-
const config = loadConfig()
|
|
13
|
-
const { moduleFileExtensions, chainBaseConfig, alias, define } = config
|
|
14
|
-
const mode = process.env.NODE_ENV as Mode
|
|
15
|
-
|
|
16
|
-
chain.mode(mode)
|
|
17
|
-
chain.module.strictExportPresence(true)
|
|
18
|
-
chain
|
|
19
|
-
.resolve
|
|
20
|
-
.modules
|
|
21
|
-
.add('node_modules')
|
|
22
|
-
.add(join(getCwd(), './node_modules'))
|
|
23
|
-
.end()
|
|
24
|
-
.extensions.merge(moduleFileExtensions)
|
|
25
|
-
.end()
|
|
26
|
-
.alias
|
|
27
|
-
.end()
|
|
28
|
-
|
|
29
|
-
alias && Object.keys(alias).forEach(item => {
|
|
30
|
-
chain.resolve.alias
|
|
31
|
-
.set(item, alias[item])
|
|
32
|
-
})
|
|
33
|
-
addCommonChain(chain, isServer)
|
|
34
|
-
setStyle(chain, /\.css$/, {
|
|
35
|
-
rule: 'css',
|
|
36
|
-
isServer,
|
|
37
|
-
importLoaders: 1
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
setStyle(chain, /\.less$/, {
|
|
41
|
-
rule: 'less',
|
|
42
|
-
loader: 'less-loader',
|
|
43
|
-
isServer,
|
|
44
|
-
importLoaders: 2
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
chain.plugin('minify-css').use(MiniCssExtractPlugin, getBuildConfig().cssBuildConfig)
|
|
48
|
-
|
|
49
|
-
chain.plugin('webpackBar').use(new WebpackBar({
|
|
50
|
-
name: isServer ? 'server' : 'client',
|
|
51
|
-
color: isServer ? '#f173ac' : '#45b97c'
|
|
52
|
-
}))
|
|
53
|
-
chain.plugin('ssrDefine').use(webpack.DefinePlugin, [{
|
|
54
|
-
...process.env,
|
|
55
|
-
__isBrowser__: !isServer,
|
|
56
|
-
...(isServer ? define?.server : define?.client),
|
|
57
|
-
...define?.base
|
|
58
|
-
}])
|
|
59
|
-
chainBaseConfig(chain, isServer)
|
|
60
|
-
return config
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export {
|
|
64
|
-
getBaseConfig
|
|
65
|
-
}
|
package/src/config/client.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { loadConfig, getSplitChunksOptions, getOutputPublicPath, loadModuleFromFramework, getBuildConfig, terserConfig, asyncChunkMap } from 'ssr-common-utils'
|
|
2
|
-
import * as WebpackChain from 'webpack-chain'
|
|
3
|
-
import { getBaseConfig } from './base'
|
|
4
|
-
|
|
5
|
-
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin')
|
|
6
|
-
const safePostCssParser = require('postcss-safe-parser')
|
|
7
|
-
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
|
|
8
|
-
const loadModule = loadModuleFromFramework
|
|
9
|
-
|
|
10
|
-
const getClientWebpack = (chain: WebpackChain) => {
|
|
11
|
-
const { isDev, chunkName, getOutput, cwd, chainClientConfig, host, fePort } = loadConfig()
|
|
12
|
-
const buildConfig = getBuildConfig()
|
|
13
|
-
|
|
14
|
-
const shouldUseSourceMap = isDev || Boolean(process.env.GENERATE_SOURCEMAP)
|
|
15
|
-
const publicPath = getOutputPublicPath()
|
|
16
|
-
getBaseConfig(chain, false)
|
|
17
|
-
chain.devtool(isDev ? 'eval-source-map' : (shouldUseSourceMap ? 'source-map' : false))
|
|
18
|
-
chain.entry(chunkName)
|
|
19
|
-
.add(require.resolve('../entry/client-entry'))
|
|
20
|
-
.end()
|
|
21
|
-
.output
|
|
22
|
-
.path(getOutput().clientOutPut)
|
|
23
|
-
.filename(buildConfig.jsBuldConfig.fileName)
|
|
24
|
-
.chunkFilename(buildConfig.jsBuldConfig.chunkFileName)
|
|
25
|
-
.publicPath(publicPath)
|
|
26
|
-
.end()
|
|
27
|
-
chain.optimization
|
|
28
|
-
.runtimeChunk(true)
|
|
29
|
-
.splitChunks(getSplitChunksOptions(asyncChunkMap))
|
|
30
|
-
.when(!isDev, optimization => {
|
|
31
|
-
optimization.minimizer('terser')
|
|
32
|
-
.use(loadModule('terser-webpack-plugin'), [terserConfig()])
|
|
33
|
-
optimization.minimizer('optimize-css').use(loadModule('optimize-css-assets-webpack-plugin'), [{
|
|
34
|
-
cssProcessorOptions: {
|
|
35
|
-
parser: safePostCssParser,
|
|
36
|
-
map: shouldUseSourceMap ? {
|
|
37
|
-
inline: false,
|
|
38
|
-
annotation: true
|
|
39
|
-
} : false
|
|
40
|
-
}
|
|
41
|
-
}])
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
chain.plugin('moduleNotFound').use(ModuleNotFoundPlugin, [cwd])
|
|
45
|
-
|
|
46
|
-
chain.plugin('manifest').use(loadModule('webpack-manifest-plugin'), [{
|
|
47
|
-
fileName: 'asset-manifest.json'
|
|
48
|
-
}])
|
|
49
|
-
|
|
50
|
-
chain.when(isDev, chain => {
|
|
51
|
-
chain.plugin('fast-refresh').use(new ReactRefreshWebpackPlugin({
|
|
52
|
-
overlay: {
|
|
53
|
-
sockHost: host,
|
|
54
|
-
sockPort: fePort
|
|
55
|
-
}
|
|
56
|
-
}))
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
chainClientConfig(chain) // 合并用户自定义配置
|
|
60
|
-
|
|
61
|
-
return chain.toConfig()
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export {
|
|
65
|
-
getClientWebpack
|
|
66
|
-
}
|
package/src/config/index.ts
DELETED
package/src/config/server.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { join } from 'path'
|
|
2
|
-
import { loadConfig, nodeExternals, loadModuleFromFramework } from 'ssr-common-utils'
|
|
3
|
-
import * as WebpackChain from 'webpack-chain'
|
|
4
|
-
import * as webpack from 'ssr-webpack4'
|
|
5
|
-
|
|
6
|
-
import { getBaseConfig } from './base'
|
|
7
|
-
|
|
8
|
-
const getServerWebpack = (chain: WebpackChain) => {
|
|
9
|
-
const config = loadConfig()
|
|
10
|
-
const { isDev, cwd, getOutput, chainServerConfig, whiteList, chunkName } = config
|
|
11
|
-
const shouldUseSourceMap = isDev || Boolean(process.env.GENERATE_SOURCEMAP)
|
|
12
|
-
getBaseConfig(chain, true)
|
|
13
|
-
chain.devtool(isDev ? 'inline-source-map' : false)
|
|
14
|
-
chain.target('node')
|
|
15
|
-
chain.entry(chunkName)
|
|
16
|
-
.add(require.resolve('../entry/server-entry'))
|
|
17
|
-
.end()
|
|
18
|
-
.output
|
|
19
|
-
.path(getOutput().serverOutPut)
|
|
20
|
-
.filename('[name].server.js')
|
|
21
|
-
.libraryTarget('commonjs')
|
|
22
|
-
|
|
23
|
-
const modulesDir = [join(cwd, './node_modules')]
|
|
24
|
-
chain.externals(nodeExternals({
|
|
25
|
-
whitelist: whiteList,
|
|
26
|
-
// externals Dir contains example/xxx/node_modules ssr/node_modules
|
|
27
|
-
modulesDir
|
|
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
|
-
}
|
|
41
|
-
chain.when(isDev, () => {
|
|
42
|
-
chain.watch(true)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
chain.plugin('serverLimit').use(webpack.optimize.LimitChunkCountPlugin, [{
|
|
46
|
-
maxChunks: 1
|
|
47
|
-
}])
|
|
48
|
-
|
|
49
|
-
chainServerConfig(chain) // 合并用户自定义配置
|
|
50
|
-
|
|
51
|
-
return chain.toConfig()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export {
|
|
55
|
-
getServerWebpack
|
|
56
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { createElement } from 'react'
|
|
2
|
-
import * as ReactDOM from 'react-dom'
|
|
3
|
-
import 'react-router' // for vite prebundle list
|
|
4
|
-
import { BrowserRouter, Route, Switch } from 'react-router-dom'
|
|
5
|
-
import { preloadComponent, isMicro, setStoreContext } from 'ssr-common-utils'
|
|
6
|
-
import { wrapComponent } from 'ssr-hoc-react'
|
|
7
|
-
import { LayoutProps } from 'ssr-types'
|
|
8
|
-
import { STORE_CONTEXT as Context } from '_build/create-context'
|
|
9
|
-
import { Routes } from './create-router'
|
|
10
|
-
import { AppContext } from './context'
|
|
11
|
-
|
|
12
|
-
const { FeRoutes, layoutFetch, App } = Routes
|
|
13
|
-
|
|
14
|
-
const clientRender = async (): Promise<void> => {
|
|
15
|
-
const IApp = App ?? function (props: LayoutProps) {
|
|
16
|
-
return props.children!
|
|
17
|
-
}
|
|
18
|
-
setStoreContext(Context)
|
|
19
|
-
// 客户端渲染||hydrate
|
|
20
|
-
const baseName = isMicro() ? window.clientPrefix : window.prefix
|
|
21
|
-
const routes = await preloadComponent(FeRoutes, baseName)
|
|
22
|
-
ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](
|
|
23
|
-
createElement(BrowserRouter, {
|
|
24
|
-
basename: baseName
|
|
25
|
-
}, createElement(AppContext as any, {
|
|
26
|
-
children: createElement(Switch, null,
|
|
27
|
-
createElement(IApp as any, null, createElement(Switch, null,
|
|
28
|
-
routes.map(item => {
|
|
29
|
-
const { fetch, component, path } = item
|
|
30
|
-
component.fetch = fetch
|
|
31
|
-
component.layoutFetch = layoutFetch
|
|
32
|
-
const WrappedComponent = wrapComponent(component)
|
|
33
|
-
return createElement(Route, {
|
|
34
|
-
exact: true,
|
|
35
|
-
key: path,
|
|
36
|
-
path: path,
|
|
37
|
-
render: () => createElement(WrappedComponent, {
|
|
38
|
-
key: location.pathname
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
}))))
|
|
42
|
-
}))
|
|
43
|
-
, document.querySelector(window.ssrDevInfo.rootId ?? '#app'))
|
|
44
|
-
if (!window.__USE_VITE__) {
|
|
45
|
-
(module as any)?.hot?.accept?.()
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
clientRender()
|
|
50
|
-
|
|
51
|
-
export {
|
|
52
|
-
clientRender
|
|
53
|
-
}
|
package/src/entry/context.tsx
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useReducer, createElement } from 'react'
|
|
2
|
-
import { IProps, Action, IWindow, ReactRoutesType } from 'ssr-types'
|
|
3
|
-
import { STORE_CONTEXT as Context } from '_build/create-context'
|
|
4
|
-
import { Routes } from './create-router'
|
|
5
|
-
|
|
6
|
-
const { reducer, state } = Routes as ReactRoutesType
|
|
7
|
-
|
|
8
|
-
const userState = state ?? {}
|
|
9
|
-
const userReducer = reducer ?? function () {}
|
|
10
|
-
|
|
11
|
-
const isDev = process.env.NODE_ENV !== 'production'
|
|
12
|
-
|
|
13
|
-
// 客户端的 context 只需要创建一次,在页面整个生命周期内共享
|
|
14
|
-
declare const window: IWindow
|
|
15
|
-
|
|
16
|
-
function defaultReducer (state: any, action: Action) {
|
|
17
|
-
switch (action.type) {
|
|
18
|
-
case 'updateContext':
|
|
19
|
-
if (isDev) {
|
|
20
|
-
console.log('[SSR:updateContext]: dispatch updateContext with action')
|
|
21
|
-
console.log(action)
|
|
22
|
-
}
|
|
23
|
-
return { ...state, ...action.payload }
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const initialState = Object.assign({}, userState ?? {}, window.__INITIAL_DATA__)
|
|
28
|
-
|
|
29
|
-
function combineReducer (state: any, action: any) {
|
|
30
|
-
return defaultReducer(state, action) || userReducer(state, action)
|
|
31
|
-
}
|
|
32
|
-
export function AppContext (props: IProps) {
|
|
33
|
-
const [state, dispatch] = useReducer(combineReducer, initialState)
|
|
34
|
-
return createElement(Context.Provider, {
|
|
35
|
-
value: {
|
|
36
|
-
state,
|
|
37
|
-
dispatch
|
|
38
|
-
}
|
|
39
|
-
}, props.children)
|
|
40
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// The file is provisional,don't modify it
|
|
2
|
-
|
|
3
|
-
import { Context, createContext } from 'react'
|
|
4
|
-
import { IContext } from 'ssr-types'
|
|
5
|
-
let STORE_CONTEXT: Context<IContext>
|
|
6
|
-
if (__isBrowser__) {
|
|
7
|
-
STORE_CONTEXT = window.STORE_CONTEXT || createContext<IContext>({
|
|
8
|
-
state: {}
|
|
9
|
-
})
|
|
10
|
-
window.STORE_CONTEXT = STORE_CONTEXT
|
|
11
|
-
} else {
|
|
12
|
-
STORE_CONTEXT = createContext<IContext>({
|
|
13
|
-
state: {}
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
STORE_CONTEXT
|
|
19
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { combineRoutes } from 'ssr-common-utils'
|
|
2
|
-
import * as declareRoutes from '_build/ssr-declare-routes'
|
|
3
|
-
import * as ManualRoutes from '_build/ssr-manual-routes'
|
|
4
|
-
import { ReactRoutesType } from 'ssr-types'
|
|
5
|
-
|
|
6
|
-
const Routes = combineRoutes(declareRoutes, ManualRoutes) as ReactRoutesType
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
Routes
|
|
10
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { PassThrough } from 'stream'
|
|
2
|
-
import * as React from 'react'
|
|
3
|
-
import { createElement } from 'react'
|
|
4
|
-
import { StaticRouter } from 'react-router-dom'
|
|
5
|
-
import { renderToString, renderToNodeStream } from 'react-dom/server'
|
|
6
|
-
import { findRoute, getManifest, logGreen, normalizePath, getAsyncCssChunk, getAsyncJsChunk, splitPageInfo, reactRefreshFragment, localStorageWrapper, checkRoute } from 'ssr-common-utils'
|
|
7
|
-
import { ISSRContext, IConfig, ReactESMPreloadFeRouteItem, DynamicFC, StaticFC } from 'ssr-types'
|
|
8
|
-
import { serialize } from 'ssr-serialize-javascript'
|
|
9
|
-
import { STORE_CONTEXT as Context } from '_build/create-context'
|
|
10
|
-
import { Routes } from './create-router'
|
|
11
|
-
|
|
12
|
-
const { FeRoutes, layoutFetch, state, Layout } = Routes
|
|
13
|
-
|
|
14
|
-
const serverRender = async (ctx: ISSRContext, config: IConfig) => {
|
|
15
|
-
const { mode, parallelFetch, prefix, isVite, isDev, clientPrefix, stream, rootId, hashRouter } = config
|
|
16
|
-
const rawPath = ctx.request.path ?? ctx.request.url
|
|
17
|
-
const path = normalizePath(rawPath, prefix)
|
|
18
|
-
const routeItem = findRoute<ReactESMPreloadFeRouteItem>(FeRoutes, path)
|
|
19
|
-
checkRoute({ routeItem, path })
|
|
20
|
-
const { fetch, webpackChunkName, component } = routeItem
|
|
21
|
-
|
|
22
|
-
const fn = async () => {
|
|
23
|
-
const dynamicCssOrder = await getAsyncCssChunk(ctx, webpackChunkName, config)
|
|
24
|
-
const dynamicJsOrder = await getAsyncJsChunk(ctx, webpackChunkName, config)
|
|
25
|
-
const manifest = await getManifest(config)
|
|
26
|
-
|
|
27
|
-
const injectCss = ((isVite && isDev) ? [
|
|
28
|
-
<script src="/@vite/client" type="module" key="vite-client" />,
|
|
29
|
-
<script key="vite-react-refresh" type="module" dangerouslySetInnerHTML={{
|
|
30
|
-
__html: reactRefreshFragment
|
|
31
|
-
}} />
|
|
32
|
-
] : dynamicCssOrder.map(css => manifest[css]).filter(Boolean).map(css => <link rel='stylesheet' key={css} href={css} />))
|
|
33
|
-
.concat((isVite && isDev) ? [] : dynamicJsOrder.map(js => manifest[js]).filter(Boolean).map(js =>
|
|
34
|
-
<link href={js} as="script" rel={isVite ? 'modulepreload' : 'preload'} key={js} />
|
|
35
|
-
))
|
|
36
|
-
|
|
37
|
-
const injectScript = [
|
|
38
|
-
...(isVite ? [<script key="viteWindowInit" dangerouslySetInnerHTML={{
|
|
39
|
-
__html: 'window.__USE_VITE__=true'
|
|
40
|
-
}} />] : []),
|
|
41
|
-
...((isVite && isDev) ? [<script type="module" src='/node_modules/ssr-plugin-react/esm/entry/client-entry.js' key="vite-react-entry" />] : []),
|
|
42
|
-
...dynamicJsOrder.map(js => manifest[js]).filter(Boolean).map(item => <script key={item} src={item} type={isVite ? 'module' : 'text/javascript'} />)
|
|
43
|
-
]
|
|
44
|
-
const staticList = {
|
|
45
|
-
injectCss,
|
|
46
|
-
injectScript
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const isCsr = !!(mode === 'csr' || ctx.request.query?.csr)
|
|
50
|
-
const Component = isCsr ? React.Fragment : (component.name === 'dynamicComponent' ? (await (component as DynamicFC)()).default : component as StaticFC)
|
|
51
|
-
|
|
52
|
-
if (isCsr) {
|
|
53
|
-
logGreen(`Current path ${path} use csr render mode`)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let [layoutFetchData, fetchData] = [{}, {}]
|
|
57
|
-
|
|
58
|
-
if (!isCsr) {
|
|
59
|
-
const currentFetch = fetch ? (await fetch()).default : null
|
|
60
|
-
const lF = layoutFetch ? layoutFetch({ ctx }) : Promise.resolve({})
|
|
61
|
-
const CF = currentFetch ? currentFetch({ ctx }) : Promise.resolve({});
|
|
62
|
-
[layoutFetchData, fetchData] = parallelFetch ? await Promise.all([lF, CF]) : [await lF, await CF]
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const combineData = isCsr ? null : Object.assign(state ?? {}, layoutFetchData ?? {}, fetchData ?? {})
|
|
66
|
-
const ssrDevInfo = { manifest: isDev ? manifest : '', rootId }
|
|
67
|
-
const innerHTML = splitPageInfo({
|
|
68
|
-
'window.__USE_SSR__': !isCsr,
|
|
69
|
-
'window.__INITIAL_DATA__': isCsr ? {} : serialize(combineData),
|
|
70
|
-
'window.__USE_VITE__': isVite,
|
|
71
|
-
'window.prefix': `"${prefix}"`,
|
|
72
|
-
'window.clientPrefix': `"${clientPrefix ?? ''}"`,
|
|
73
|
-
'window.ssrDevInfo': JSON.stringify(ssrDevInfo),
|
|
74
|
-
'window.hashRouter': Boolean(hashRouter)
|
|
75
|
-
})
|
|
76
|
-
const injectState = <script dangerouslySetInnerHTML={{ __html: innerHTML }} />
|
|
77
|
-
// with jsx type error, use createElement here
|
|
78
|
-
const ele = createElement(StaticRouter, {
|
|
79
|
-
location: ctx.request.url,
|
|
80
|
-
basename: prefix === '/' ? undefined : prefix
|
|
81
|
-
}, createElement(Context.Provider, {
|
|
82
|
-
value: {
|
|
83
|
-
state: combineData
|
|
84
|
-
}
|
|
85
|
-
}, createElement(Layout, {
|
|
86
|
-
ctx: ctx,
|
|
87
|
-
config: config,
|
|
88
|
-
staticList: staticList,
|
|
89
|
-
injectState: injectState
|
|
90
|
-
}, createElement(Component, null))))
|
|
91
|
-
// for ctx.body will loose asynclocalstorage context, consume stream in advance like vue2/3
|
|
92
|
-
return stream ? renderToNodeStream(ele).pipe(new PassThrough()) : renderToString(ele)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return await localStorageWrapper.run({
|
|
96
|
-
context: Context,
|
|
97
|
-
ctx
|
|
98
|
-
}, fn)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export {
|
|
102
|
-
serverRender,
|
|
103
|
-
Routes
|
|
104
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from 'ssr-common-utils'
|
|
2
|
-
|
|
3
|
-
const { isVite, optimize } = loadConfig()
|
|
4
|
-
const spinner = require('ora')('Building')
|
|
5
|
-
|
|
6
|
-
export function clientPlugin () {
|
|
7
|
-
return {
|
|
8
|
-
name: 'plugin-react',
|
|
9
|
-
start: async () => {
|
|
10
|
-
if (isVite) {
|
|
11
|
-
const { viteStart } = await import('./tools/vite')
|
|
12
|
-
await viteStart()
|
|
13
|
-
} else {
|
|
14
|
-
if (optimize) {
|
|
15
|
-
spinner.start()
|
|
16
|
-
const { viteBuildClient } = await import('./tools/vite')
|
|
17
|
-
await viteBuildClient()
|
|
18
|
-
process.env.NODE_ENV = 'development'
|
|
19
|
-
spinner.stop()
|
|
20
|
-
const { webpackStart } = await import('./tools/webpack')
|
|
21
|
-
await webpackStart()
|
|
22
|
-
} else {
|
|
23
|
-
const { webpackStart } = await import('./tools/webpack')
|
|
24
|
-
await webpackStart()
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
build: async () => {
|
|
29
|
-
if (isVite) {
|
|
30
|
-
const { viteBuild } = await import('./tools/vite')
|
|
31
|
-
await viteBuild()
|
|
32
|
-
} else {
|
|
33
|
-
if (optimize) {
|
|
34
|
-
spinner.start()
|
|
35
|
-
const { viteBuildClient } = await import('./tools/vite')
|
|
36
|
-
await viteBuildClient()
|
|
37
|
-
spinner.stop()
|
|
38
|
-
const { webpackBuild } = await import('./tools/webpack')
|
|
39
|
-
await webpackBuild()
|
|
40
|
-
} else {
|
|
41
|
-
const { webpackBuild } = await import('./tools/webpack')
|
|
42
|
-
await webpackBuild()
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export * from './tools/vite'
|