ssr-plugin-react 6.1.21 → 6.1.23

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,44 @@
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.23](https://github.com/zhangyuang/ssr/compare/v6.1.22...v6.1.23) (2021-12-13)
7
+
8
+
9
+ ### Features
10
+
11
+ * support alias config ([551c9be](https://github.com/zhangyuang/ssr/commit/551c9be1741f63443381cc897166fb640fa8718d))
12
+
13
+
14
+
15
+
16
+
17
+ ## [6.1.22](https://github.com/zhangyuang/ssr/compare/v6.1.22-alpha.1...v6.1.22) (2021-12-11)
18
+
19
+ **Note:** Version bump only for package ssr-plugin-react
20
+
21
+
22
+
23
+
24
+
25
+ ## [6.1.22-alpha.1](https://github.com/zhangyuang/ssr/compare/v6.1.22-alpha.0...v6.1.22-alpha.1) (2021-12-11)
26
+
27
+
28
+ ### Features
29
+
30
+ * support vite-style-import ([62d936b](https://github.com/zhangyuang/ssr/commit/62d936b62dd47365be8eb27564628adc139b619d))
31
+
32
+
33
+
34
+
35
+
36
+ ## [6.1.22-alpha.0](https://github.com/zhangyuang/ssr/compare/v6.1.21...v6.1.22-alpha.0) (2021-12-10)
37
+
38
+ **Note:** Version bump only for package ssr-plugin-react
39
+
40
+
41
+
42
+
43
+
6
44
  ## [6.1.21](https://github.com/zhangyuang/ssr/compare/v6.1.20...v6.1.21) (2021-12-09)
7
45
 
8
46
  **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/ECwdFhkCwm6NE1c_jP-DOYaVaR8K_ORJeEzFlDW9eBJj8igF3yeut9KnoChxyqJ4ReJogCG9bL_qZ3OYdZBI0w" width="300">
276
+ <img src="https://res.wx.qq.com/op_res/i1X1OIr2VfQ9MLcvsFOCyN4UWghSc85u64U8OeXxQWKrpdXvpnhe-gms1sUgtRr_QOHZPqanJ2G_lNzuN00ZvQ" width="300">
277
277
  </div>
278
278
 
279
279
  ## 前端开发手册
@@ -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, corejs, babelExtraModule } = config;
46
+ const { moduleFileExtensions, useHash, isDev, chainBaseConfig, corejs, babelExtraModule, alias } = config;
47
47
  const mode = process.env.NODE_ENV;
48
48
  const envOptions = {
49
49
  modules: false
@@ -78,6 +78,10 @@ const getBaseConfig = (chain, isServer) => {
78
78
  .set('react', loadModule('react')) // 用cwd的路径alias,否则可能会出现多个react实例
79
79
  .set('react-router', loadModule('react-router'))
80
80
  .set('react-router-dom', loadModule('react-router-dom'));
81
+ alias && Object.keys(alias).forEach(item => {
82
+ chain.resolve.alias
83
+ .set(item, alias[item]);
84
+ });
81
85
  (0, ssr_server_utils_1.addImageChain)(chain, isServer);
82
86
  const babelModule = chain.module
83
87
  .rule('compileBabel')
@@ -22,7 +22,7 @@ const getServerWebpack = (chain) => {
22
22
  const modulesDir = [(0, path_1.join)(cwd, './node_modules')];
23
23
  modulesDir.push((0, ssr_server_utils_1.getLocalNodeModules)());
24
24
  chain.externals((0, ssr_server_utils_1.nodeExternals)({
25
- whitelist: [/\.(css|less|sass|scss)$/, /antd.*?(style)/].concat(whiteList || []),
25
+ whitelist: whiteList,
26
26
  // externals Dir contains example/xxx/node_modules ssr/node_modules
27
27
  modulesDir
28
28
  }));
package/cjs/tools/vite.js CHANGED
@@ -4,9 +4,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.clientConfig = exports.serverConfig = exports.viteStart = exports.viteBuild = void 0;
5
5
  const ssr_server_utils_1 = require("ssr-server-utils");
6
6
  const plugin_react_1 = require("@vitejs/plugin-react");
7
+ const vite_plugin_style_import_1 = require("vite-plugin-style-import");
7
8
  const build = require('vite').build;
8
9
  const { getOutput, reactServerEntry, reactClientEntry, viteConfig } = (0, ssr_server_utils_1.loadConfig)();
9
10
  const { clientOutPut, serverOutPut } = getOutput();
11
+ const styleImportConfig = {
12
+ include: ['**/*.vue', '**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx', /chunkName/],
13
+ resolves: [
14
+ (0, vite_plugin_style_import_1.AndDesignVueResolve)(),
15
+ (0, vite_plugin_style_import_1.VantResolve)(),
16
+ (0, vite_plugin_style_import_1.ElementPlusResolve)(),
17
+ (0, vite_plugin_style_import_1.NutuiResolve)(),
18
+ (0, vite_plugin_style_import_1.AntdResolve)()
19
+ ]
20
+ };
10
21
  const serverConfig = {
11
22
  ...(0, ssr_server_utils_1.commonConfig)(),
12
23
  plugins: [
@@ -14,7 +25,8 @@ const serverConfig = {
14
25
  ...(_b = (_a = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _a === void 0 ? void 0 : _a.server) === null || _b === void 0 ? void 0 : _b.defaultPluginOptions,
15
26
  jsxRuntime: 'classic'
16
27
  }),
17
- (_d = (_c = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _c === void 0 ? void 0 : _c.server) === null || _d === void 0 ? void 0 : _d.extraPlugin
28
+ (_d = (_c = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _c === void 0 ? void 0 : _c.server) === null || _d === void 0 ? void 0 : _d.extraPlugin,
29
+ (0, vite_plugin_style_import_1.default)(styleImportConfig)
18
30
  ],
19
31
  build: {
20
32
  ssr: reactServerEntry,
@@ -41,14 +53,15 @@ const clientConfig = {
41
53
  ...(_h = (_g = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _g === void 0 ? void 0 : _g.client) === null || _h === void 0 ? void 0 : _h.defaultPluginOptions,
42
54
  jsxRuntime: 'classic'
43
55
  }),
44
- (_k = (_j = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _j === void 0 ? void 0 : _j.client) === null || _k === void 0 ? void 0 : _k.extraPlugin
56
+ (_k = (_j = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _j === void 0 ? void 0 : _j.client) === null || _k === void 0 ? void 0 : _k.extraPlugin,
57
+ (0, vite_plugin_style_import_1.default)(styleImportConfig)
45
58
  ],
46
59
  build: {
47
60
  ssrManifest: true,
48
61
  outDir: clientOutPut,
49
62
  rollupOptions: {
50
63
  input: reactClientEntry,
51
- output: ssr_server_utils_1.output,
64
+ output: ssr_server_utils_1.rollupOutputOptions,
52
65
  plugins: [(0, ssr_server_utils_1.chunkNamePlugin)(), (0, ssr_server_utils_1.manifestPlugin)()]
53
66
  }
54
67
  },
@@ -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, corejs, babelExtraModule } = config;
43
+ const { moduleFileExtensions, useHash, isDev, chainBaseConfig, corejs, babelExtraModule, alias } = config;
44
44
  const mode = process.env.NODE_ENV;
45
45
  const envOptions = {
46
46
  modules: false
@@ -75,6 +75,10 @@ const getBaseConfig = (chain, isServer) => {
75
75
  .set('react', loadModule('react')) // 用cwd的路径alias,否则可能会出现多个react实例
76
76
  .set('react-router', loadModule('react-router'))
77
77
  .set('react-router-dom', loadModule('react-router-dom'));
78
+ alias && Object.keys(alias).forEach(item => {
79
+ chain.resolve.alias
80
+ .set(item, alias[item]);
81
+ });
78
82
  addImageChain(chain, isServer);
79
83
  const babelModule = chain.module
80
84
  .rule('compileBabel')
@@ -19,7 +19,7 @@ const getServerWebpack = (chain) => {
19
19
  const modulesDir = [join(cwd, './node_modules')];
20
20
  modulesDir.push(getLocalNodeModules());
21
21
  chain.externals(nodeExternals({
22
- whitelist: [/\.(css|less|sass|scss)$/, /antd.*?(style)/].concat(whiteList || []),
22
+ whitelist: whiteList,
23
23
  // externals Dir contains example/xxx/node_modules ssr/node_modules
24
24
  modulesDir
25
25
  }));
package/esm/tools/vite.js CHANGED
@@ -1,9 +1,20 @@
1
1
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
2
- import { loadConfig, chunkNamePlugin, output, manifestPlugin, commonConfig } from 'ssr-server-utils';
2
+ import { loadConfig, chunkNamePlugin, rollupOutputOptions, manifestPlugin, commonConfig } from 'ssr-server-utils';
3
3
  import react from '@vitejs/plugin-react';
4
+ import styleImport, { AndDesignVueResolve, VantResolve, ElementPlusResolve, NutuiResolve, AntdResolve } from 'vite-plugin-style-import';
4
5
  const build = require('vite').build;
5
6
  const { getOutput, reactServerEntry, reactClientEntry, viteConfig } = loadConfig();
6
7
  const { clientOutPut, serverOutPut } = getOutput();
8
+ const styleImportConfig = {
9
+ include: ['**/*.vue', '**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx', /chunkName/],
10
+ resolves: [
11
+ AndDesignVueResolve(),
12
+ VantResolve(),
13
+ ElementPlusResolve(),
14
+ NutuiResolve(),
15
+ AntdResolve()
16
+ ]
17
+ };
7
18
  const serverConfig = {
8
19
  ...commonConfig(),
9
20
  plugins: [
@@ -11,7 +22,8 @@ const serverConfig = {
11
22
  ...(_b = (_a = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _a === void 0 ? void 0 : _a.server) === null || _b === void 0 ? void 0 : _b.defaultPluginOptions,
12
23
  jsxRuntime: 'classic'
13
24
  }),
14
- (_d = (_c = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _c === void 0 ? void 0 : _c.server) === null || _d === void 0 ? void 0 : _d.extraPlugin
25
+ (_d = (_c = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _c === void 0 ? void 0 : _c.server) === null || _d === void 0 ? void 0 : _d.extraPlugin,
26
+ styleImport(styleImportConfig)
15
27
  ],
16
28
  build: {
17
29
  ssr: reactServerEntry,
@@ -37,14 +49,15 @@ const clientConfig = {
37
49
  ...(_h = (_g = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _g === void 0 ? void 0 : _g.client) === null || _h === void 0 ? void 0 : _h.defaultPluginOptions,
38
50
  jsxRuntime: 'classic'
39
51
  }),
40
- (_k = (_j = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _j === void 0 ? void 0 : _j.client) === null || _k === void 0 ? void 0 : _k.extraPlugin
52
+ (_k = (_j = viteConfig === null || viteConfig === void 0 ? void 0 : viteConfig()) === null || _j === void 0 ? void 0 : _j.client) === null || _k === void 0 ? void 0 : _k.extraPlugin,
53
+ styleImport(styleImportConfig)
41
54
  ],
42
55
  build: {
43
56
  ssrManifest: true,
44
57
  outDir: clientOutPut,
45
58
  rollupOptions: {
46
59
  input: reactClientEntry,
47
- output: output,
60
+ output: rollupOutputOptions,
48
61
  plugins: [chunkNamePlugin(), manifestPlugin()]
49
62
  }
50
63
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssr-plugin-react",
3
- "version": "6.1.21",
3
+ "version": "6.1.23",
4
4
  "description": "plugin-react for ssr",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -54,13 +54,14 @@
54
54
  "postcss-safe-parser": "4.0.1",
55
55
  "react-dev-utils": "^11.0.4",
56
56
  "serialize-javascript": "^6.0.0",
57
- "ssr-client-utils": "^6.1.18",
58
- "ssr-hoc-react": "^6.1.18",
59
- "ssr-server-utils": "^6.1.21",
60
- "ssr-webpack": "^6.1.21",
57
+ "ssr-client-utils": "^6.1.23",
58
+ "ssr-hoc-react": "^6.1.23",
59
+ "ssr-server-utils": "^6.1.23",
60
+ "ssr-webpack": "^6.1.23",
61
61
  "terser-webpack-plugin": "^2.3.5",
62
62
  "url-loader": "^4.1.1",
63
63
  "vite": "^2.7.0-beta.10",
64
+ "vite-plugin-style-import": "^1.4.0",
64
65
  "webpack-bundle-analyzer": "^3.6.1",
65
66
  "webpack-chain": "^6.4.0",
66
67
  "webpack-manifest-plugin": "^2.2.0",
@@ -71,7 +72,7 @@
71
72
  "@types/react-dom": "^17.0.0",
72
73
  "@types/react-router-dom": "^5.1.3",
73
74
  "@types/webpack": "^4.41.10",
74
- "ssr-types-react": "^6.1.18"
75
+ "ssr-types-react": "^6.1.23"
75
76
  },
76
- "gitHead": "8a6eb76df0a07597839e867ad5dd2fec13f3a92f"
77
+ "gitHead": "9340f68013419d44ebe3d4c44d6d1ce3a35c68ed"
77
78
  }
@@ -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, corejs, babelExtraModule } = config
48
+ const { moduleFileExtensions, useHash, isDev, chainBaseConfig, corejs, babelExtraModule, alias } = config
49
49
  const mode = process.env.NODE_ENV as Mode
50
50
  const envOptions = {
51
51
  modules: false
@@ -82,6 +82,11 @@ const getBaseConfig = (chain: WebpackChain, isServer: boolean) => {
82
82
  .set('react-router', loadModule('react-router'))
83
83
  .set('react-router-dom', loadModule('react-router-dom'))
84
84
 
85
+ alias && Object.keys(alias).forEach(item => {
86
+ chain.resolve.alias
87
+ .set(item, alias[item])
88
+ })
89
+
85
90
  addImageChain(chain, isServer)
86
91
 
87
92
  const babelModule = chain.module
@@ -23,7 +23,7 @@ const getServerWebpack = (chain: WebpackChain) => {
23
23
  const modulesDir = [join(cwd, './node_modules')]
24
24
  modulesDir.push(getLocalNodeModules())
25
25
  chain.externals(nodeExternals({
26
- whitelist: [/\.(css|less|sass|scss)$/, /antd.*?(style)/].concat(whiteList as RegExp[] || []),
26
+ whitelist: whiteList,
27
27
  // externals Dir contains example/xxx/node_modules ssr/node_modules
28
28
  modulesDir
29
29
  }))
package/src/tools/vite.ts CHANGED
@@ -1,10 +1,26 @@
1
1
  import type { build as BuildType, UserConfig } from 'vite'
2
- import { loadConfig, chunkNamePlugin, output, manifestPlugin, commonConfig } from 'ssr-server-utils'
2
+ import { loadConfig, chunkNamePlugin, rollupOutputOptions, manifestPlugin, commonConfig } from 'ssr-server-utils'
3
3
  import react from '@vitejs/plugin-react'
4
+ import styleImport, {
5
+ AndDesignVueResolve,
6
+ VantResolve,
7
+ ElementPlusResolve,
8
+ NutuiResolve,
9
+ AntdResolve
10
+ } from 'vite-plugin-style-import'
11
+
4
12
  const build: typeof BuildType = require('vite').build
5
13
  const { getOutput, reactServerEntry, reactClientEntry, viteConfig } = loadConfig()
6
14
  const { clientOutPut, serverOutPut } = getOutput()
7
-
15
+ const styleImportConfig = {
16
+ include: ['**/*.vue', '**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx', /chunkName/],
17
+ resolves: [
18
+ AndDesignVueResolve(),
19
+ VantResolve(),
20
+ ElementPlusResolve(),
21
+ NutuiResolve(),
22
+ AntdResolve()]
23
+ }
8
24
  const serverConfig: UserConfig = {
9
25
  ...commonConfig(),
10
26
  plugins: [
@@ -12,7 +28,9 @@ const serverConfig: UserConfig = {
12
28
  ...viteConfig?.()?.server?.defaultPluginOptions,
13
29
  jsxRuntime: 'classic'
14
30
  }),
15
- viteConfig?.()?.server?.extraPlugin
31
+ viteConfig?.()?.server?.extraPlugin,
32
+ styleImport(styleImportConfig)
33
+
16
34
  ],
17
35
  build: {
18
36
  ssr: reactServerEntry,
@@ -39,14 +57,15 @@ const clientConfig: UserConfig = {
39
57
  ...viteConfig?.()?.client?.defaultPluginOptions,
40
58
  jsxRuntime: 'classic'
41
59
  }),
42
- viteConfig?.()?.client?.extraPlugin
60
+ viteConfig?.()?.client?.extraPlugin,
61
+ styleImport(styleImportConfig)
43
62
  ],
44
63
  build: {
45
64
  ssrManifest: true,
46
65
  outDir: clientOutPut,
47
66
  rollupOptions: {
48
67
  input: reactClientEntry,
49
- output: output,
68
+ output: rollupOutputOptions,
50
69
  plugins: [chunkNamePlugin(), manifestPlugin()]
51
70
  }
52
71
  },