ssr-plugin-react 6.2.84 → 6.2.85
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 +19 -0
- package/cjs/config/base.d.ts +1 -1
- package/cjs/config/base.d.ts.map +1 -1
- package/cjs/config/base.js +9 -16
- package/cjs/config/base.js.map +1 -1
- package/cjs/config/client.d.ts +1 -1
- package/cjs/config/client.d.ts.map +1 -1
- package/cjs/config/client.js +18 -21
- package/cjs/config/client.js.map +1 -1
- package/cjs/config/server.d.ts +1 -1
- package/cjs/config/server.d.ts.map +1 -1
- package/cjs/config/server.js +9 -12
- package/cjs/config/server.js.map +1 -1
- package/cjs/entry/client-entry.d.ts.map +1 -1
- package/cjs/entry/client-entry.js +2 -1
- package/cjs/entry/client-entry.js.map +1 -1
- package/cjs/entry/context.d.ts.map +1 -1
- package/cjs/entry/context.js.map +1 -1
- package/cjs/entry/create.d.ts.map +1 -1
- package/cjs/entry/create.js +4 -4
- package/cjs/entry/create.js.map +1 -1
- package/cjs/entry/server-entry.d.ts.map +1 -1
- package/cjs/entry/server-entry.js +29 -13
- package/cjs/entry/server-entry.js.map +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/tools/vite.d.ts.map +1 -1
- package/cjs/tools/vite.js +11 -20
- package/cjs/tools/vite.js.map +1 -1
- package/cjs/tools/webpack.js.map +1 -1
- package/esm/config/base.d.ts +1 -1
- package/esm/config/base.d.ts.map +1 -1
- package/esm/config/base.js +10 -17
- package/esm/config/base.js.map +1 -1
- package/esm/config/client.d.ts +1 -1
- package/esm/config/client.d.ts.map +1 -1
- package/esm/config/client.js +19 -22
- package/esm/config/client.js.map +1 -1
- package/esm/config/server.d.ts +1 -1
- package/esm/config/server.d.ts.map +1 -1
- package/esm/config/server.js +9 -12
- package/esm/config/server.js.map +1 -1
- package/esm/entry/client-entry.d.ts.map +1 -1
- package/esm/entry/client-entry.js +2 -1
- package/esm/entry/client-entry.js.map +1 -1
- package/esm/entry/context.d.ts.map +1 -1
- package/esm/entry/context.js.map +1 -1
- package/esm/entry/create.d.ts.map +1 -1
- package/esm/entry/create.js +4 -4
- package/esm/entry/create.js.map +1 -1
- package/esm/entry/server-entry.d.ts.map +1 -1
- package/esm/entry/server-entry.js +29 -13
- package/esm/entry/server-entry.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/tools/vite.d.ts.map +1 -1
- package/esm/tools/vite.js +12 -21
- package/esm/tools/vite.js.map +1 -1
- package/esm/tools/webpack.js.map +1 -1
- package/package.json +1 -1
- package/src/config/base.ts +47 -55
- package/src/config/client.ts +52 -55
- package/src/config/server.ts +31 -36
- package/src/entry/client-entry.tsx +54 -38
- package/src/entry/context.tsx +22 -19
- package/src/entry/create.ts +19 -19
- package/src/entry/server-entry.tsx +115 -82
- package/src/index.ts +41 -41
- package/src/tools/vite.ts +103 -122
- package/src/tools/webpack.ts +12 -12
package/src/config/base.ts
CHANGED
|
@@ -1,65 +1,57 @@
|
|
|
1
|
-
|
|
2
1
|
import { join } from 'path'
|
|
2
|
+
import { addCommonChain, getBuildConfig, getCwd, loadConfig, loadModuleFromFramework, setStyle } from 'ssr-common-utils'
|
|
3
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
4
|
import * as webpack from 'ssr-webpack4'
|
|
5
|
+
import WebpackChain from 'webpack-chain'
|
|
7
6
|
|
|
8
7
|
const MiniCssExtractPlugin = require(loadModuleFromFramework('ssr-mini-css-extract-plugin'))
|
|
9
8
|
const WebpackBar = require('webpackbar')
|
|
10
9
|
|
|
11
10
|
const getBaseConfig = (chain: WebpackChain, isServer: boolean) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
...(isServer ? define?.server : define?.client),
|
|
57
|
-
...define?.base
|
|
58
|
-
}])
|
|
59
|
-
chainBaseConfig(chain, isServer)
|
|
60
|
-
return config
|
|
11
|
+
const config = loadConfig()
|
|
12
|
+
const { moduleFileExtensions, chainBaseConfig, alias, define } = config
|
|
13
|
+
const mode = process.env.NODE_ENV as Mode
|
|
14
|
+
|
|
15
|
+
chain.mode(mode)
|
|
16
|
+
chain.module.strictExportPresence(true)
|
|
17
|
+
chain.resolve.modules.add('node_modules').add(join(getCwd(), './node_modules')).end().extensions.merge(moduleFileExtensions).end().alias.end()
|
|
18
|
+
|
|
19
|
+
alias &&
|
|
20
|
+
Object.keys(alias).forEach((item) => {
|
|
21
|
+
chain.resolve.alias.set(item, alias[item])
|
|
22
|
+
})
|
|
23
|
+
addCommonChain(chain, isServer)
|
|
24
|
+
setStyle(chain, /\.css$/, {
|
|
25
|
+
rule: 'css',
|
|
26
|
+
isServer,
|
|
27
|
+
importLoaders: 1
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
setStyle(chain, /\.less$/, {
|
|
31
|
+
rule: 'less',
|
|
32
|
+
loader: 'less-loader',
|
|
33
|
+
isServer,
|
|
34
|
+
importLoaders: 2
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
chain.plugin('minify-css').use(MiniCssExtractPlugin, getBuildConfig().cssBuildConfig)
|
|
38
|
+
|
|
39
|
+
chain.plugin('webpackBar').use(
|
|
40
|
+
new WebpackBar({
|
|
41
|
+
name: isServer ? 'server' : 'client',
|
|
42
|
+
color: isServer ? '#f173ac' : '#45b97c'
|
|
43
|
+
})
|
|
44
|
+
)
|
|
45
|
+
chain.plugin('ssrDefine').use(webpack.DefinePlugin, [
|
|
46
|
+
{
|
|
47
|
+
...process.env,
|
|
48
|
+
__isBrowser__: !isServer,
|
|
49
|
+
...(isServer ? define?.server : define?.client),
|
|
50
|
+
...define?.base
|
|
51
|
+
}
|
|
52
|
+
])
|
|
53
|
+
chainBaseConfig(chain, isServer)
|
|
54
|
+
return config
|
|
61
55
|
}
|
|
62
56
|
|
|
63
|
-
export {
|
|
64
|
-
getBaseConfig
|
|
65
|
-
}
|
|
57
|
+
export { getBaseConfig }
|
package/src/config/client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { asyncChunkMap, getBuildConfig, getOutputPublicPath, getSplitChunksOptions, loadConfig, loadModuleFromFramework, terserConfig } from 'ssr-common-utils'
|
|
2
|
+
import WebpackChain from 'webpack-chain'
|
|
3
3
|
import { getBaseConfig } from './base'
|
|
4
4
|
|
|
5
5
|
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin')
|
|
@@ -8,58 +8,55 @@ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'
|
|
|
8
8
|
const loadModule = loadModuleFromFramework
|
|
9
9
|
|
|
10
10
|
const getClientWebpack = (chain: WebpackChain) => {
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return chain.toConfig()
|
|
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.entry(chunkName).add(require.resolve('../entry/client-entry')).end().output.path(getOutput().clientOutPut).filename(buildConfig.jsBuldConfig.fileName).chunkFilename(buildConfig.jsBuldConfig.chunkFileName).publicPath(publicPath).end()
|
|
18
|
+
chain.optimization
|
|
19
|
+
.runtimeChunk(true)
|
|
20
|
+
.splitChunks(getSplitChunksOptions(asyncChunkMap))
|
|
21
|
+
.when(!isDev, (optimization) => {
|
|
22
|
+
optimization.minimizer('terser').use(loadModule('terser-webpack-plugin'), [terserConfig(false)])
|
|
23
|
+
optimization.minimizer('optimize-css').use(loadModule('optimize-css-assets-webpack-plugin'), [
|
|
24
|
+
{
|
|
25
|
+
cssProcessorOptions: {
|
|
26
|
+
parser: safePostCssParser,
|
|
27
|
+
map: shouldUseSourceMap
|
|
28
|
+
? {
|
|
29
|
+
inline: false,
|
|
30
|
+
annotation: true
|
|
31
|
+
}
|
|
32
|
+
: false
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
])
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
chain.plugin('moduleNotFound').use(ModuleNotFoundPlugin, [cwd])
|
|
39
|
+
|
|
40
|
+
chain.plugin('manifest').use(loadModule('webpack-manifest-plugin'), [
|
|
41
|
+
{
|
|
42
|
+
fileName: 'asset-manifest.json'
|
|
43
|
+
}
|
|
44
|
+
])
|
|
45
|
+
|
|
46
|
+
chain.when(isDev, (chain) => {
|
|
47
|
+
chain.plugin('fast-refresh').use(
|
|
48
|
+
new ReactRefreshWebpackPlugin({
|
|
49
|
+
overlay: {
|
|
50
|
+
sockHost: host,
|
|
51
|
+
sockPort: fePort
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
chainClientConfig(chain) // 合并用户自定义配置
|
|
58
|
+
|
|
59
|
+
return chain.toConfig()
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
export {
|
|
64
|
-
getClientWebpack
|
|
65
|
-
}
|
|
62
|
+
export { getClientWebpack }
|
package/src/config/server.ts
CHANGED
|
@@ -1,48 +1,43 @@
|
|
|
1
1
|
import { loadConfig, loadModuleFromFramework } from 'ssr-common-utils'
|
|
2
|
-
import * as WebpackChain from 'webpack-chain'
|
|
3
2
|
import * as webpack from 'ssr-webpack4'
|
|
3
|
+
import WebpackChain from 'webpack-chain'
|
|
4
4
|
|
|
5
5
|
import { getBaseConfig } from './base'
|
|
6
6
|
|
|
7
7
|
const getServerWebpack = (chain: WebpackChain) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.add(require.resolve('../entry/server-entry'))
|
|
15
|
-
.end()
|
|
16
|
-
.output
|
|
17
|
-
.path(getOutput().serverOutPut)
|
|
18
|
-
.filename('[name].server.js')
|
|
19
|
-
.libraryTarget('commonjs')
|
|
8
|
+
const config = loadConfig()
|
|
9
|
+
const { isDev, getOutput, chainServerConfig, chunkName } = config
|
|
10
|
+
const shouldUseSourceMap = isDev || Boolean(process.env.GENERATE_SOURCEMAP)
|
|
11
|
+
getBaseConfig(chain, true)
|
|
12
|
+
chain.target('node')
|
|
13
|
+
chain.entry(chunkName).add(require.resolve('../entry/server-entry')).end().output.path(getOutput().serverOutPut).filename('[name].server.js').libraryTarget('commonjs')
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
15
|
+
if (!isDev) {
|
|
16
|
+
chain.optimization.minimizer('terser').use(loadModuleFromFramework('terser-webpack-plugin'), [
|
|
17
|
+
{
|
|
18
|
+
terserOptions: {
|
|
19
|
+
keep_fnames: true
|
|
20
|
+
},
|
|
21
|
+
extractComments: false,
|
|
22
|
+
parallel: true,
|
|
23
|
+
cache: true,
|
|
24
|
+
sourceMap: shouldUseSourceMap
|
|
25
|
+
}
|
|
26
|
+
])
|
|
27
|
+
}
|
|
28
|
+
chain.when(isDev, () => {
|
|
29
|
+
chain.watch(true)
|
|
30
|
+
})
|
|
36
31
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
chain.plugin('serverLimit').use(webpack.optimize.LimitChunkCountPlugin, [
|
|
33
|
+
{
|
|
34
|
+
maxChunks: 1
|
|
35
|
+
}
|
|
36
|
+
])
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
chainServerConfig(chain) // 合并用户自定义配置
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
return chain.toConfig()
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
export {
|
|
47
|
-
getServerWebpack
|
|
48
|
-
}
|
|
43
|
+
export { getServerWebpack }
|
|
@@ -11,45 +11,61 @@ import { AppContext } from './context'
|
|
|
11
11
|
const { FeRoutes, layoutFetch, App } = Routes
|
|
12
12
|
|
|
13
13
|
const clientRender = async (): Promise<void> => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
14
|
+
const IApp =
|
|
15
|
+
App ??
|
|
16
|
+
function (props: LayoutProps) {
|
|
17
|
+
return props.children!
|
|
18
|
+
}
|
|
19
|
+
const context = ssrCreateContext() as any
|
|
20
|
+
setStoreContext(context)
|
|
21
|
+
const store = createStore(window.__VALTIO_DATA__)
|
|
22
|
+
setStore(store ?? {})
|
|
23
|
+
const baseName = isMicro() ? window.clientPrefix : window.prefix
|
|
24
|
+
const routes = await preloadComponent(FeRoutes, baseName)
|
|
25
|
+
ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](
|
|
26
|
+
createElement(
|
|
27
|
+
BrowserRouter,
|
|
28
|
+
{
|
|
29
|
+
basename: baseName
|
|
30
|
+
},
|
|
31
|
+
createElement(AppContext, {
|
|
32
|
+
context,
|
|
33
|
+
children: createElement(
|
|
34
|
+
Switch,
|
|
35
|
+
null,
|
|
36
|
+
createElement(
|
|
37
|
+
IApp as any,
|
|
38
|
+
null,
|
|
39
|
+
createElement(
|
|
40
|
+
Switch,
|
|
41
|
+
null,
|
|
42
|
+
routes.map((item) => {
|
|
43
|
+
const { fetch, component, path } = item
|
|
44
|
+
component.fetch = fetch
|
|
45
|
+
component.layoutFetch = layoutFetch
|
|
46
|
+
const WrappedComponent = wrapComponent(component)
|
|
47
|
+
return createElement(Route, {
|
|
48
|
+
exact: true,
|
|
49
|
+
key: path,
|
|
50
|
+
path: path,
|
|
51
|
+
render: () =>
|
|
52
|
+
createElement(WrappedComponent, {
|
|
53
|
+
key: location.pathname
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
})
|
|
61
|
+
),
|
|
62
|
+
document.querySelector(window.ssrDevInfo.rootId ?? '#app')
|
|
63
|
+
)
|
|
64
|
+
if (!window.__USE_VITE__) {
|
|
65
|
+
;(module as any)?.hot?.accept?.()
|
|
66
|
+
}
|
|
49
67
|
}
|
|
50
68
|
|
|
51
69
|
clientRender()
|
|
52
70
|
|
|
53
|
-
export {
|
|
54
|
-
clientRender
|
|
55
|
-
}
|
|
71
|
+
export { clientRender }
|
package/src/entry/context.tsx
CHANGED
|
@@ -5,35 +5,38 @@ import { Routes } from './create'
|
|
|
5
5
|
const { reducer, state } = Routes as ReactRoutesType
|
|
6
6
|
|
|
7
7
|
const userState = state ?? {}
|
|
8
|
-
const userReducer = reducer ?? function() {
|
|
8
|
+
const userReducer = reducer ?? function () {}
|
|
9
9
|
|
|
10
10
|
const isDev = process.env.NODE_ENV !== 'production'
|
|
11
11
|
|
|
12
12
|
declare const window: IWindow
|
|
13
13
|
|
|
14
14
|
function defaultReducer(state: any, action: Action) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
switch (action.type) {
|
|
16
|
+
case 'updateContext':
|
|
17
|
+
if (isDev) {
|
|
18
|
+
console.log('[SSR:updateContext]: dispatch updateContext with action')
|
|
19
|
+
console.log(action)
|
|
20
|
+
}
|
|
21
|
+
return { ...state, ...action.payload }
|
|
22
|
+
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
25
|
function combineReducer(state: any, action: any) {
|
|
27
|
-
|
|
26
|
+
return defaultReducer(state, action) || userReducer(state, action)
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
export function AppContext(props: IProps) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
const initialState = Object.assign({}, userState ?? {}, __isBrowser__ ? window?.__INITIAL_DATA__ : props.initialState)
|
|
31
|
+
const [state, dispatch] = useReducer(combineReducer, initialState)
|
|
32
|
+
return createElement(
|
|
33
|
+
props.context.Provider,
|
|
34
|
+
{
|
|
35
|
+
value: {
|
|
36
|
+
state,
|
|
37
|
+
dispatch
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
props.children as any
|
|
41
|
+
)
|
|
39
42
|
}
|
package/src/entry/create.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { createContext } from 'react'
|
|
2
|
-
import type { IContext } from 'ssr-types'
|
|
3
|
-
import { proxy } from 'valtio'
|
|
4
|
-
import { deepClone } from 'ssr-deepclone'
|
|
5
|
-
import { combineRoutes } from 'ssr-common-utils'
|
|
6
1
|
import * as declareRoutes from '_build/ssr-declare-routes'
|
|
7
2
|
import * as ManualRoutes from '_build/ssr-manual-routes'
|
|
3
|
+
import { createContext } from 'react'
|
|
4
|
+
import { combineRoutes } from 'ssr-common-utils'
|
|
5
|
+
import { deepClone } from 'ssr-deepclone'
|
|
6
|
+
import type { IContext } from 'ssr-types'
|
|
8
7
|
import { ReactRoutesType } from 'ssr-types'
|
|
8
|
+
import { proxy } from 'valtio'
|
|
9
9
|
|
|
10
10
|
export const Routes = combineRoutes(declareRoutes, ManualRoutes) as ReactRoutesType
|
|
11
11
|
|
|
12
12
|
export const ssrCreateContext = () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
const STORE_CONTEXT = createContext<IContext>({
|
|
14
|
+
state: {}
|
|
15
|
+
})
|
|
16
|
+
if (__isBrowser__) {
|
|
17
|
+
window.STORE_CONTEXT = STORE_CONTEXT
|
|
18
|
+
}
|
|
19
|
+
return STORE_CONTEXT
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export function createStore
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
export function createStore(initialData?: any) {
|
|
23
|
+
const { store } = Routes
|
|
24
|
+
const storeInstance = initialData ? store : deepClone(store)
|
|
25
|
+
for (const key in storeInstance) {
|
|
26
|
+
storeInstance[key] = initialData ? proxy(initialData[key]) : proxy(storeInstance[key])
|
|
27
|
+
}
|
|
28
|
+
return storeInstance
|
|
29
29
|
}
|