From 5b274a69f05cf4931d26dc0442818a56528c9e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=8D=E9=81=A5?= <49544090+SunLxy@users.noreply.github.com> Date: Tue, 29 Mar 2022 16:55:17 +0800 Subject: [PATCH] released v3.1.9 (#30) --- core/README.md | 25 +++++++++++++++---- core/package.json | 2 +- core/src/index.ts | 3 --- core/src/overrides/index.ts | 20 +++------------ core/src/overrides/path.ts | 19 ++++++++++++++ core/src/utils/ProcessingConfig.ts | 5 ++-- example/basic-plugins/package.json | 6 ++--- example/basic-routes-rematch-new/package.json | 4 +-- example/basic-routes/package.json | 4 +-- example/basic/package.json | 4 +-- example/react-router-rematch-old/package.json | 8 +++--- lerna.json | 2 +- packages/create-kkt-ssr/package.json | 2 +- packages/kkt-plugin-less/package.json | 2 +- packages/kkt-plugin-ssr/package.json | 4 +-- packages/react-ssr-enhanced/package.json | 2 +- 16 files changed, 65 insertions(+), 47 deletions(-) create mode 100644 core/src/overrides/path.ts diff --git a/core/README.md b/core/README.md index cc39b85..7cdbffd 100644 --- a/core/README.md +++ b/core/README.md @@ -100,7 +100,7 @@ Add `.kktrc.js` to the root directory of your project ```ts import pluginLess from "@kkt/plugin-less" -import { Options } from "@kkt/ssr/lib/overrides" +import { Options } from "@kkt/ssr/lib/interface" export default { @@ -128,7 +128,7 @@ Add `.kktssrrc.js` to the root directory of your project **Rewrite Client Config** ```ts -import { Options } from "@kkt/ssr/lib/overrides" +import { Options } from "@kkt/ssr/lib/interface" export default { @@ -148,7 +148,7 @@ export default { 3. `output.library.type`: The default is `commonjs`, ```ts -import { Options } from "@kkt/ssr/lib/overrides" +import { Options } from "@kkt/ssr/lib/interface" export default { @@ -164,7 +164,7 @@ export default { **More Webpack Config** ```ts -import { Options } from "@kkt/ssr/lib/overrides" +import { Options } from "@kkt/ssr/lib/interface" export default { @@ -195,7 +195,7 @@ export default { **Rewrite Paths** -[other paths](https://github.com/kktjs/ssr/blob/d13656cfad29d2baa857d339ae5e70434f43f9d3/core/src/overrides/pathUtils.ts#L5-L29) +[other paths](https://github.com/kktjs/ssr/blob/4376baf1b5c365709addb313c4dd3ee314734baa/core/src/interface.ts#L6-L30) ```js export default { @@ -282,6 +282,21 @@ export default { The root directory creates the `.kktssrrc.js` file. +| 参数 | 类型 | 默认值 | 说明 | +| -------- | -------- | --------------- | --------- | +| overridesClientWebpack | `(conf: webpack.Configuration, env: "development" \| "production", options: Options) => webpack.Configuration` | `undefined` | 覆写客户端配置 | +| overridesServerWebpack | `(conf: webpack.Configuration, env: "development" \| "production", options: Options) => webpack.Configuration` | `undefined` | 覆写服务端配置 | +| overridesCommonWebpack | `(conf: webpack.Configuration, env: "development" \| "production", options: Options) => webpack.Configuration`| `undefined` | 公共覆盖配置 | +| overridesWebpack| `(conf: webpack.Configuration[], env: "development" \| "production", options: Options) => webpack.Configuration[] \| webpack.Configuration` | `{}`| 最终的配置 | +| server_path | `string` | `src/server.js` | 服务端打包入口 | +| client_path | `string`| `src/client.js` | 客户端打包入口 | +| output_path| `string` | `dist` | 输出文件地址 | +| isUseOriginalConfig| `boolean` | `false` | 是否使用原始 react-script 下的配置 | +| isUseServerConfig | `boolean` | `true` | 是否需要 server 配置 | +| paths | `Partial` | `{}` | [paths 脚本中webpack配置 使用的地址](https://github.com/kktjs/ssr/blob/4376baf1b5c365709addb313c4dd3ee314734baa/core/src/interface.ts#L6-L30) | +| watchOptions| `webpack.Configuration["watchOptions"]`| `{}`| watch 配置 | +| proxySetup | `(app:Application)=>({path:stirng\|string[],options:MockerOption})` | `undefined`| [mock 代理配置](https://github.com/jaywcjlove/mocker-api) | + ```js // Modify the webpack config export default { diff --git a/core/package.json b/core/package.json index ae13501..84e67bb 100644 --- a/core/package.json +++ b/core/package.json @@ -1,6 +1,6 @@ { "name": "@kkt/ssr", - "version": "3.1.8", + "version": "3.1.9", "description": "", "license": "MIT", "main": "lib/index.js", diff --git a/core/src/index.ts b/core/src/index.ts index 9b2b3fb..94258fa 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -114,9 +114,6 @@ interface SSRNCCArgs extends BuildArgs { miniServer, miniClient } - console.log(options) - process.exit(1) - // 解决 使用 react-scripts 原始情况下 PUBLIC_URL 报错 if (!Reflect.has(process.env || {}, "PUBLIC_URL")) { process.env.PUBLIC_URL = ''; diff --git a/core/src/overrides/index.ts b/core/src/overrides/index.ts index 2f14b74..0c8d81b 100644 --- a/core/src/overrides/index.ts +++ b/core/src/overrides/index.ts @@ -1,11 +1,10 @@ // 获取 根目录下 自己定义的配置 - import fs from 'fs'; -import { resolveModule, resolveApp, paths } from "./pathUtils" - +import { resolveModule, resolveApp, } from "./pathUtils" import { restENV } from "./env" -import { overridePaths, } from 'kkt/lib/overrides/paths'; import { OverridesProps } from "./../interface" +import paths from "./path" + const tsOptions = { compilerOptions: { @@ -79,19 +78,8 @@ export async function loaderConf(): Promise { restENV(overrides) // 重写 paths 值 - const path = { - ...paths, - ...overrides.paths, - appBuild: overrides.output_path - } - if (!fs.existsSync(path.appIndexJs)) { - path.appIndexJs = overrides.client_path - } + const path = paths(overrides) overrides.paths = path - // 覆盖配置 里面的地址 - overridePaths(undefined, { - ...(path as unknown as Record) - }); return overrides; } catch (error) { const message = error && error.message ? error.message : ''; diff --git a/core/src/overrides/path.ts b/core/src/overrides/path.ts new file mode 100644 index 0000000..46205c4 --- /dev/null +++ b/core/src/overrides/path.ts @@ -0,0 +1,19 @@ +import { reactScripts } from "./pathUtils" +import { Paths, OverridesProps } from "../interface" +import fs from 'fs'; + +/** 覆盖 */ +export default (overrides: OverridesProps): Paths => { + const pathsConfPath = `${reactScripts}/config/paths`; + const pathsConf = require(pathsConfPath); + const newPaths = { + ...pathsConf, + ...overrides.paths, + appBuild: overrides.output_path + } + if (!fs.existsSync(newPaths.appIndexJs) && fs.existsSync(overrides.client_path)) { + newPaths.appIndexJs = overrides.client_path + } + require.cache[require.resolve(`${reactScripts}/config/paths`)].exports = newPaths + return newPaths +} \ No newline at end of file diff --git a/core/src/utils/ProcessingConfig.ts b/core/src/utils/ProcessingConfig.ts index d758147..1bf33f8 100644 --- a/core/src/utils/ProcessingConfig.ts +++ b/core/src/utils/ProcessingConfig.ts @@ -1,5 +1,4 @@ // 重置 create-react-app 中的 react-script配置 -import { reactScripts, webpackConfigPath } from "../overrides/pathUtils" import webpackNodeExternals from "webpack-node-externals" import webpack from "webpack" import { OptionsProps, OverridesProps } from "../interface" @@ -87,13 +86,13 @@ const getWebpackConfig: GetWebpackConfig = (newConfig, type, overrides, nodeExte newConfig.externals = [webpackNodeExternals()] } - if (options.miniServer && type === "server") { + if (!options.miniServer && type === "server") { /** server 端 去除代码压缩 */ newConfig.optimization.minimize = false newConfig.optimization.minimizer = [] } - if (options.miniClient && type === "client") { + if (!options.miniClient && type === "client") { /** client 端 去除代码压缩 */ newConfig.optimization.minimize = false newConfig.optimization.minimizer = [] diff --git a/example/basic-plugins/package.json b/example/basic-plugins/package.json index fa1f9e8..81aba2a 100644 --- a/example/basic-plugins/package.json +++ b/example/basic-plugins/package.json @@ -1,6 +1,6 @@ { "name": "@examples/basic-plugins", - "version": "3.1.8", + "version": "3.1.9", "description": "", "private": true, "scripts": { @@ -16,7 +16,7 @@ "react-dom": "17.0.2" }, "devDependencies": { - "@kkt/plugin-ssr": "3.1.8", + "@kkt/plugin-ssr": "3.1.9", "kkt": "~7.1.5" }, "browserslist": { @@ -31,4 +31,4 @@ "last 1 safari version" ] } -} \ No newline at end of file +} diff --git a/example/basic-routes-rematch-new/package.json b/example/basic-routes-rematch-new/package.json index 529c4a9..0d800e2 100644 --- a/example/basic-routes-rematch-new/package.json +++ b/example/basic-routes-rematch-new/package.json @@ -1,6 +1,6 @@ { "name": "@examples/basic-routes-rematch-new", - "version": "3.1.8", + "version": "3.1.9", "description": "", "private": true, "scripts": { @@ -22,7 +22,7 @@ "serialize-javascript": "6.0.0" }, "devDependencies": { - "@kkt/ssr": "3.1.8", + "@kkt/ssr": "3.1.9", "kkt": "~7.1.5" }, "browserslist": { diff --git a/example/basic-routes/package.json b/example/basic-routes/package.json index ae0aa42..afe3c8d 100644 --- a/example/basic-routes/package.json +++ b/example/basic-routes/package.json @@ -1,6 +1,6 @@ { "name": "@examples/basic-routes", - "version": "3.1.8", + "version": "3.1.9", "description": "", "private": true, "scripts": { @@ -18,7 +18,7 @@ "react-router-dom": "^6.2.2" }, "devDependencies": { - "@kkt/ssr": "3.1.8", + "@kkt/ssr": "3.1.9", "kkt": "~7.1.5" }, "browserslist": { diff --git a/example/basic/package.json b/example/basic/package.json index 3b80aba..32eb7e8 100644 --- a/example/basic/package.json +++ b/example/basic/package.json @@ -1,6 +1,6 @@ { "name": "@examples/basic", - "version": "3.1.8", + "version": "3.1.9", "description": "", "private": true, "scripts": { @@ -16,7 +16,7 @@ "react-dom": "17.0.2" }, "devDependencies": { - "@kkt/ssr": "3.1.8", + "@kkt/ssr": "3.1.9", "kkt": "~7.1.5" }, "browserslist": { diff --git a/example/react-router-rematch-old/package.json b/example/react-router-rematch-old/package.json index ef033d5..f293e74 100644 --- a/example/react-router-rematch-old/package.json +++ b/example/react-router-rematch-old/package.json @@ -1,6 +1,6 @@ { "name": "@examples/basic-routes-rematch-old", - "version": "3.1.8", + "version": "3.1.9", "description": "", "private": true, "scripts": { @@ -15,7 +15,7 @@ "author": "Kenny Wong ", "license": "MIT", "dependencies": { - "@kkt/react-ssr-enhanced": "3.1.8", + "@kkt/react-ssr-enhanced": "3.1.9", "@rematch/core": "2.2.0", "axios": "0.26.0", "cookie-parser": "1.4.3", @@ -31,8 +31,8 @@ "redux": "4.1.2" }, "devDependencies": { - "@kkt/plugin-less": "3.1.8", - "@kkt/ssr": "3.1.8", + "@kkt/plugin-less": "3.1.9", + "@kkt/ssr": "3.1.9", "assert": "2.0.0", "browserify-zlib": "0.2.0", "buffer": "6.0.3", diff --git a/lerna.json b/lerna.json index e077f57..755c06a 100644 --- a/lerna.json +++ b/lerna.json @@ -7,7 +7,7 @@ "packages/kkt-plugin-less", "packages/kkt-plugin-ssr" ], - "version": "3.1.8", + "version": "3.1.9", "command": { "create": { "license": "MIT" diff --git a/packages/create-kkt-ssr/package.json b/packages/create-kkt-ssr/package.json index 54fd17c..0fd6fdf 100644 --- a/packages/create-kkt-ssr/package.json +++ b/packages/create-kkt-ssr/package.json @@ -1,6 +1,6 @@ { "name": "create-kkt-ssr", - "version": "3.1.8", + "version": "3.1.9", "description": "CLI tool to bootstrap KKT applications with no configuration", "main": "lib/index.js", "bin": { diff --git a/packages/kkt-plugin-less/package.json b/packages/kkt-plugin-less/package.json index 993c045..13ce0ef 100644 --- a/packages/kkt-plugin-less/package.json +++ b/packages/kkt-plugin-less/package.json @@ -1,6 +1,6 @@ { "name": "@kkt/plugin-less", - "version": "3.1.8", + "version": "3.1.9", "description": "Support less.", "main": "lib/index.js", "module": "esm/index.js", diff --git a/packages/kkt-plugin-ssr/package.json b/packages/kkt-plugin-ssr/package.json index e3520d0..a2b4aac 100644 --- a/packages/kkt-plugin-ssr/package.json +++ b/packages/kkt-plugin-ssr/package.json @@ -1,6 +1,6 @@ { "name": "@kkt/plugin-ssr", - "version": "3.1.8", + "version": "3.1.9", "description": "", "main": "lib/index.js", "module": "esm/index.js", @@ -36,4 +36,4 @@ "webpack-node-externals": "^3.0.0", "webpackbar": "^5.0.2" } -} \ No newline at end of file +} diff --git a/packages/react-ssr-enhanced/package.json b/packages/react-ssr-enhanced/package.json index 40ad757..43f4d75 100644 --- a/packages/react-ssr-enhanced/package.json +++ b/packages/react-ssr-enhanced/package.json @@ -1,6 +1,6 @@ { "name": "@kkt/react-ssr-enhanced", - "version": "3.1.8", + "version": "3.1.9", "description": "KKT react server side rendering enhancement tool.", "main": "lib/index.js", "module": "esm/index.js",