ssr-plugin-react 6.1.38 → 6.1.42

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
+ ## [6.1.42](https://github.com/zhangyuang/ssr/compare/v6.1.41...v6.1.42) (2022-01-05)
7
+
8
+
9
+ ### Features
10
+
11
+ * support config.define ([c04f128](https://github.com/zhangyuang/ssr/commit/c04f12844e22300f57e17683cff0584e8f8ea123))
12
+
13
+
14
+
15
+
16
+
17
+ ## [6.1.41](https://github.com/zhangyuang/ssr/compare/v6.1.40...v6.1.41) (2022-01-05)
18
+
19
+ **Note:** Version bump only for package ssr-plugin-react
20
+
21
+
22
+
23
+
24
+
25
+ ## [6.1.40](https://github.com/zhangyuang/ssr/compare/v6.1.39...v6.1.40) (2022-01-04)
26
+
27
+ **Note:** Version bump only for package ssr-plugin-react
28
+
29
+
30
+
31
+
32
+
33
+ ## [6.1.39](https://github.com/zhangyuang/ssr/compare/v6.1.38...v6.1.39) (2021-12-31)
34
+
35
+ **Note:** Version bump only for package ssr-plugin-react
36
+
37
+
38
+
39
+
40
+
6
41
  ## [6.1.38](https://github.com/zhangyuang/ssr/compare/v6.1.37...v6.1.38) (2021-12-31)
7
42
 
8
43
 
@@ -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 = require.resolve;
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;
@@ -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 = require.resolve;
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(loadModule('../entry/client-entry'))
21
+ .add(require.resolve('../entry/client-entry'))
22
22
  .end()
23
23
  .output
24
24
  .path(getOutput().clientOutPut)
@@ -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(loadModule('../entry/server-entry'))
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;
@@ -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 = require.resolve;
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;
@@ -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 = require.resolve;
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(loadModule('../entry/client-entry'))
18
+ .add(require.resolve('../entry/client-entry'))
19
19
  .end()
20
20
  .output
21
21
  .path(getOutput().clientOutPut)
@@ -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(loadModule('../entry/server-entry'))
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.38",
3
+ "version": "6.1.42",
4
4
  "description": "plugin-react for ssr",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -56,10 +56,10 @@
56
56
  "postcss-safe-parser": "4.0.1",
57
57
  "react-dev-utils": "^11.0.4",
58
58
  "serialize-javascript": "^6.0.0",
59
- "ssr-client-utils": "^6.1.38",
60
- "ssr-hoc-react": "^6.1.38",
61
- "ssr-server-utils": "^6.1.38",
62
- "ssr-webpack": "^6.1.38",
59
+ "ssr-client-utils": "^6.1.42",
60
+ "ssr-hoc-react": "^6.1.42",
61
+ "ssr-server-utils": "^6.1.42",
62
+ "ssr-webpack": "^6.1.42",
63
63
  "terser-webpack-plugin": "^2.3.5",
64
64
  "url-loader": "^4.1.1",
65
65
  "vite": "^2.7.0",
@@ -74,7 +74,7 @@
74
74
  "@types/react-dom": "^17.0.0",
75
75
  "@types/react-router-dom": "^5.1.3",
76
76
  "@types/webpack": "^4.41.10",
77
- "ssr-types-react": "^6.1.38"
77
+ "ssr-types-react": "^6.1.42"
78
78
  },
79
- "gitHead": "f5d08ca254370d85cc17914d940187b4b06b2a4a"
79
+ "gitHead": "3426bffd013456e7b72ba73f1f04a9a73855bc27"
80
80
  }
@@ -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 = require.resolve
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
@@ -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 = require.resolve
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(loadModule('../entry/client-entry'))
21
+ .add(require.resolve('../entry/client-entry'))
22
22
  .end()
23
23
  .output
24
24
  .path(getOutput().clientOutPut)
@@ -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(loadModule('../entry/server-entry'))
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 () => {