Skip to content

Commit

Permalink
released v3.1.9 (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunLxy authored Mar 29, 2022
1 parent 4376baf commit 5b274a6
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 47 deletions.
25 changes: 20 additions & 5 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 {

Expand All @@ -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 {

Expand All @@ -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 {

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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>` | `{}` | [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 {
Expand Down
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kkt/ssr",
"version": "3.1.8",
"version": "3.1.9",
"description": "",
"license": "MIT",
"main": "lib/index.js",
Expand Down
3 changes: 0 additions & 3 deletions core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
20 changes: 4 additions & 16 deletions core/src/overrides/index.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -79,19 +78,8 @@ export async function loaderConf(): Promise<OverridesProps> {
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<string, string>)
});
return overrides;
} catch (error) {
const message = error && error.message ? error.message : '';
Expand Down
19 changes: 19 additions & 0 deletions core/src/overrides/path.ts
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 2 additions & 3 deletions core/src/utils/ProcessingConfig.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 = []
Expand Down
6 changes: 3 additions & 3 deletions example/basic-plugins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@examples/basic-plugins",
"version": "3.1.8",
"version": "3.1.9",
"description": "",
"private": true,
"scripts": {
Expand All @@ -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": {
Expand All @@ -31,4 +31,4 @@
"last 1 safari version"
]
}
}
}
4 changes: 2 additions & 2 deletions example/basic-routes-rematch-new/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@examples/basic-routes-rematch-new",
"version": "3.1.8",
"version": "3.1.9",
"description": "",
"private": true,
"scripts": {
Expand All @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions example/basic-routes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@examples/basic-routes",
"version": "3.1.8",
"version": "3.1.9",
"description": "",
"private": true,
"scripts": {
Expand All @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions example/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@examples/basic",
"version": "3.1.8",
"version": "3.1.9",
"description": "",
"private": true,
"scripts": {
Expand All @@ -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": {
Expand Down
8 changes: 4 additions & 4 deletions example/react-router-rematch-old/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@examples/basic-routes-rematch-old",
"version": "3.1.8",
"version": "3.1.9",
"description": "",
"private": true,
"scripts": {
Expand All @@ -15,7 +15,7 @@
"author": "Kenny Wong <wowohoo@qq.com>",
"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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"packages/kkt-plugin-less",
"packages/kkt-plugin-ssr"
],
"version": "3.1.8",
"version": "3.1.9",
"command": {
"create": {
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-kkt-ssr/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/kkt-plugin-less/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/kkt-plugin-ssr/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -36,4 +36,4 @@
"webpack-node-externals": "^3.0.0",
"webpackbar": "^5.0.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/react-ssr-enhanced/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 5b274a6

Please sign in to comment.