Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.1.7 新增 & 修复 #26

Merged
merged 154 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
fc19528
feat:新增 @kkt/plugin-ssr
SunLxy Feb 28, 2022
e122892
chore:修改部分配置
SunLxy Mar 1, 2022
5d5f0c3
feat:新增第二种ssr-plugin方案
SunLxy Mar 2, 2022
47f3643
fix:子程序去除MiniCssExtractPlugin module和plugin
SunLxy Mar 3, 2022
047747b
fix:整理 代码
SunLxy Mar 3, 2022
a078c59
fix:修改配置
SunLxy Mar 3, 2022
d1479f0
fix:暂时处理css的sourceMap
SunLxy Mar 3, 2022
dfaeb9b
fix:先删除其他demo
SunLxy Mar 4, 2022
f16eae4
fix:插件直接运行一个webpack可以打包了
SunLxy Mar 5, 2022
6b053d1
feat:添加 @kkt/ssr-ncc
SunLxy Mar 6, 2022
10a3f55
fix:整理文件
SunLxy Mar 6, 2022
41fc8b7
fix:修改log提示
SunLxy Mar 6, 2022
ebf5dbe
feat:完善
SunLxy Mar 6, 2022
089be6e
fix:简化代码
SunLxy Mar 6, 2022
7cc3822
style:注释
SunLxy Mar 6, 2022
62d4707
feat:完善 ssr plugin 插件
SunLxy Mar 7, 2022
31c8d38
feat:添加 plugins demo
SunLxy Mar 7, 2022
b5ba4ab
doc:更新文档
SunLxy Mar 7, 2022
819eacd
fix:修改 plugins 打包 报错
SunLxy Mar 7, 2022
1daf1f2
feat:优化 plugin 代码
SunLxy Mar 7, 2022
512231d
delete:删除无用代码
SunLxy Mar 7, 2022
305f75a
feat:ci脚本
SunLxy Mar 7, 2022
b96d83f
fix:文件清空问题
SunLxy Mar 7, 2022
4893f9c
fix: sourceMap 配置
SunLxy Mar 7, 2022
741d1a7
feat:添加一个define变量
SunLxy Mar 7, 2022
0f72133
released v3.0.0
SunLxy Mar 7, 2022
d575ca8
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 7, 2022
57cdaac
delete:删除文件
SunLxy Mar 7, 2022
16eb826
delete:package-lock.json
SunLxy Mar 7, 2022
d5d14f6
feat:简单加一个 router 跳转的demo
SunLxy Mar 7, 2022
386c0e8
fix:路由渲染
SunLxy Mar 7, 2022
3e97159
fix:修改 开发模式下不需要 进行操作文件
SunLxy Mar 7, 2022
19a1f0a
feat:暂时写一个快捷生成项目的create-kkt-ssr
SunLxy Mar 7, 2022
30747fd
delete:删除无用代码
SunLxy Mar 8, 2022
2ac44fa
fix:服务端代码分割问题
SunLxy Mar 8, 2022
b366132
feat: 状态获取 demo
SunLxy Mar 8, 2022
9546cab
feat:对WebpackManifestPlugin插件生成的 asset-manifest.json 内容进行覆写
SunLxy Mar 8, 2022
e46f179
feat:新增 老版 react-router-rematch 案例
SunLxy Mar 8, 2022
867d49f
update:ci脚本
SunLxy Mar 8, 2022
9104dc6
released v3.0.1
SunLxy Mar 8, 2022
146bf60
script:修改命令
SunLxy Mar 8, 2022
ac93dfb
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 8, 2022
5c61a89
chore:更新案例react-content-loader包的版本
SunLxy Mar 8, 2022
0696349
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 8, 2022
a207f1d
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 8, 2022
00c9b39
doc:更新文档
SunLxy Mar 8, 2022
206b622
update:新增 zip ci
SunLxy Mar 8, 2022
95bf30c
update:ci
SunLxy Mar 8, 2022
581cc0c
update:ci
SunLxy Mar 8, 2022
6296d52
update:ci
SunLxy Mar 8, 2022
3a7ac3d
update:ci
SunLxy Mar 8, 2022
4735ecf
update:ci
SunLxy Mar 8, 2022
2bed730
update:ci
SunLxy Mar 8, 2022
d8786af
update:ci
SunLxy Mar 8, 2022
2b787c1
update:ci
SunLxy Mar 8, 2022
ba0e6d6
update:ci
SunLxy Mar 8, 2022
615f99b
update:ci
SunLxy Mar 8, 2022
28f56e3
update:ci
SunLxy Mar 8, 2022
d503e71
chore:管理依赖版本
SunLxy Mar 8, 2022
de4b37a
doc:更新文档
SunLxy Mar 9, 2022
041b98b
delete:删除无用代码
SunLxy Mar 9, 2022
6569830
doc:更新文档
SunLxy Mar 9, 2022
7530923
feat:使用 router v6 重构 react-ssr-enhanced
SunLxy Mar 9, 2022
38f0e21
fix:修改 @kkt/react-ssr-enhanced 包状态
SunLxy Mar 9, 2022
af476d0
question: @kkt/react-ssr-enhanced 剩余问题
SunLxy Mar 9, 2022
1bf612e
style:删除注释
SunLxy Mar 10, 2022
e52f213
fix:修改 models 报错
SunLxy Mar 10, 2022
a0d69e6
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 10, 2022
89ba625
fix:暂时解决 window 变量问题
SunLxy Mar 10, 2022
07c8873
fix:懒加载问题
SunLxy Mar 10, 2022
44ef372
released v3.0.2
SunLxy Mar 10, 2022
c384b9e
style:注释内容
SunLxy Mar 10, 2022
2fee19f
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 10, 2022
2061c3f
fix:修复 ico 图标问题
SunLxy Mar 10, 2022
9c4b83d
fix:修改 开发模式 下报错
SunLxy Mar 10, 2022
eb885dd
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 10, 2022
2931da0
fix:修改 开发模式下 ico 图标问题
SunLxy Mar 10, 2022
9b7b936
feat:二次对@kkt/ssr 进行改造 使其一次可以执行多配置
SunLxy Mar 15, 2022
80c4a76
feat: build 打印
SunLxy Mar 15, 2022
3bb40a7
fix:自定义配置加载方式,修改 build 代码
SunLxy Mar 16, 2022
54a392e
script:修改案例命令
SunLxy Mar 16, 2022
4648ec5
doc:更新文档
SunLxy Mar 16, 2022
1d01d23
fix:修改help提示
SunLxy Mar 16, 2022
80cd3dc
script:修改案例script
SunLxy Mar 16, 2022
7816223
fix:修改配置
SunLxy Mar 16, 2022
0551244
doc:更新文档
SunLxy Mar 16, 2022
779a13a
fix:加载自定义配置问题
SunLxy Mar 16, 2022
712a349
feat:新增命令行 控制是否添加 webpackNodeExternals
SunLxy Mar 16, 2022
080bd1a
feat: 增加 Args 参数
SunLxy Mar 16, 2022
b79895a
fix:判断文件入口是否存在进行添加webpack config
SunLxy Mar 16, 2022
6f83c26
released v3.1.0
SunLxy Mar 16, 2022
49caf08
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 16, 2022
edefdf9
fix:修改 paths 引用
SunLxy Mar 16, 2022
7b70012
fix:修改代码分割判断
SunLxy Mar 17, 2022
6c93b4e
fix:修改 watch 获取 webpack 配置模式,解决css问题
SunLxy Mar 17, 2022
6010b36
fix:修改开发模式下 css 服务端 加载问题
SunLxy Mar 17, 2022
204afa1
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 17, 2022
fa2a7bc
feat:内置 less 处理
SunLxy Mar 17, 2022
20b038d
fix:去除 less 处理
SunLxy Mar 18, 2022
084cbf9
refactor(@kkt/plugin-less):重构
SunLxy Mar 18, 2022
3cdce1e
fix:修改加载问题
SunLxy Mar 18, 2022
8ec6b84
update(ci):更新
SunLxy Mar 18, 2022
ebaa693
released v3.1.1
SunLxy Mar 18, 2022
d4945f9
fix(@kkt/plugin-less ): sourceMap 问题
SunLxy Mar 18, 2022
0789043
fix:开发模式下页面样式问题
SunLxy Mar 18, 2022
863a985
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 18, 2022
0984108
released v3.1.2
SunLxy Mar 18, 2022
274e2ea
update:更新script配置
SunLxy Mar 18, 2022
81ec8a3
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 18, 2022
4db937a
fix: less-loader 规则位置问题
SunLxy Mar 18, 2022
a3f47b8
fix:less 服务端className 名称问题
SunLxy Mar 19, 2022
6dcc538
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 19, 2022
15795c3
fix:更改ci
SunLxy Mar 19, 2022
0dc7d6c
fix:修改 less/css 加载问题
SunLxy Mar 19, 2022
d31df77
relesaed v3.1.3
SunLxy Mar 19, 2022
80f5c2d
fix(@kkt/ssr):css 重置参数名称问题
SunLxy Mar 19, 2022
cb6af1e
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 19, 2022
b90a2d1
fix(@kkt/react-ssr-enhanced):修复页面二次刷新 数据预获取
SunLxy Mar 21, 2022
ebaa176
feat(@kkt/ssr):新增 proxySetup 功能
SunLxy Mar 21, 2022
232e102
released v3.1.4
SunLxy Mar 21, 2022
8bde9a7
ci:更新ci
SunLxy Mar 21, 2022
4d994d9
feat(@kkt/ssr):自动启动服务
SunLxy Mar 21, 2022
d808db7
feat:start命令生成 server 文件 和 client 端 assets文件
SunLxy Mar 22, 2022
d213df6
fix(@kkt/react-ssr-enhanced):修复build后页面空白问题
SunLxy Mar 22, 2022
65d8b31
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 22, 2022
f10feb9
fix:修复 运行 start 之后关闭后 重新运行 watch 报错
SunLxy Mar 22, 2022
83ce659
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 22, 2022
9656da4
style:注释说明
SunLxy Mar 22, 2022
9f8d908
fix:修复路由配置中element为dom标签是获取不到 获取预加载数据的方法
SunLxy Mar 22, 2022
8949836
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 22, 2022
94c4691
released v3.1.5
SunLxy Mar 22, 2022
0e1a4be
released v3.1.5
SunLxy Mar 22, 2022
252a182
Merge branch 'master' of github.com:SunLxy/kkt-ssr
SunLxy Mar 22, 2022
20fc0ad
fix:修改 asset 文件生成少前面的 /
SunLxy Mar 22, 2022
df7bc4c
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 22, 2022
22300a7
chore:修复依赖
SunLxy Mar 22, 2022
6cbc5be
feat(@kkt/ssr): 移除 webpack 配置中 source-map-loader
SunLxy Mar 23, 2022
c048a02
fix(@kkt/plugin-less):修复 getLocalIdent 值
SunLxy Mar 23, 2022
dd2537f
doc:更新文档
SunLxy Mar 23, 2022
16be4ab
feat(@kkt/react-ssr-enhanced):新增传递 match 参数
SunLxy Mar 23, 2022
3d534a0
released v3.1.6
SunLxy Mar 23, 2022
a0734d0
doc:更新文档
SunLxy Mar 23, 2022
713f09e
chore:删除不需要的依赖
SunLxy Mar 23, 2022
e65e768
chore:依赖更新
SunLxy Mar 23, 2022
401d3a1
feat:新增 命令参数 控制客户端是否不使用内置的处理配置方法
SunLxy Mar 23, 2022
eaa8937
fix(@kkt/ssr):修复 Conflicting values for 'process.env.PUBLIC_URL'
SunLxy Mar 23, 2022
4deef29
style:注释
SunLxy Mar 23, 2022
d0cffd3
feat:新增 overridesCommonWebpack 配置参数
SunLxy Mar 24, 2022
3211215
feat:新增 minify 参数
SunLxy Mar 24, 2022
348d763
feat(@kkt/ssr): 新增 DefinePlugin 变量 HOSTAPI 值
SunLxy Mar 24, 2022
cdd88ee
Merge branch 'master' of github.com:kktjs/kkt-ssr
SunLxy Mar 24, 2022
2f1fa69
feat(@kkt/ssr): 新增 process.env.HOSTAPI 变量
SunLxy Mar 24, 2022
d0147fd
released v3.1.7
SunLxy Mar 24, 2022
c7d332a
style:修改案例配置
SunLxy Mar 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kkt/ssr",
"version": "3.1.6",
"version": "3.1.7",
"description": "",
"license": "MIT",
"main": "lib/index.js",
Expand All @@ -27,8 +27,8 @@
},
"dependencies": {
"@babel/core": "^7.17.8",
"@babel/runtime": "^7.17.8",
"@babel/register": "^7.17.7",
"@babel/runtime": "^7.17.8",
"babel-preset-react-app": "^10.0.1",
"css-loader": "^6.7.1",
"kkt": "^7.1.5",
Expand All @@ -42,4 +42,4 @@
"webpack-node-externals": "^3.0.0",
"webpackbar": "^5.0.2"
}
}
}
30 changes: 23 additions & 7 deletions core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
process.env.FAST_REFRESH = 'false';
process.env.BUILD_PATH = "dist"


import minimist from 'minimist';
import { BuildArgs } from 'kkt';
import { OptionsProps } from "./interface"

function help() {
const { version } = require('../package.json');
Expand All @@ -18,6 +18,9 @@ function help() {
console.log(' --s-st, --s-split ', 'server Split code .');
console.log(' --c-st, --c-split ', 'client Split code .');
console.log(' -o, --original ', 'Use original react-scripts .');
console.log(' -m, --minify ', 'All Minify output.');
console.log(' --s-m, --s-minify ', 'server Minify output.');
console.log(' --c-m, --c-minify ', 'clinet Minify output.');

console.log('\n Example:\n');
console.log(' $ \x1b[35mkkt-ssr\x1b[0m build');
Expand All @@ -33,15 +36,21 @@ function help() {

interface SSRNCCArgs extends BuildArgs {
"s-ne"?: boolean;
"s-m"?: boolean;
"s-minify"?: boolean;
"s-nodeExternals"?: boolean,
"s-st"?: boolean,
"s-split"?: boolean,
"c-ne"?: boolean;
"c-nodeExternals"?: boolean,
"c-st"?: boolean,
"c-split"?: boolean,
"c-m"?: boolean;
"c-minify"?: boolean;
"o"?: boolean,
"original"?: boolean,
"m"?: boolean;
"minify"?: boolean,
}

(async () => {
Expand Down Expand Up @@ -84,17 +93,24 @@ interface SSRNCCArgs extends BuildArgs {
// 使用原始 react-scripts
const original = argvs["o"] || argvs["original"]

const options = {
const mini = argvs["m"] || argvs["minify"]

const miniServer = mini || argvs["s-m"] || argvs["s-minify"]
const miniClient = mini || argvs["c-m"] || argvs["c-minify"]

const options: OptionsProps = {
clientNodeExternals,
serverNodeExternals,
clientIsChunk,
serverIsChunk,
original
original,
mini,
miniServer,
miniClient
}
// 解决 原始情况下 PUBLIC_URL 报错
if (argvs["PUBLIC_URL"]) {
process.env.PUBLIC_URL = argvs["PUBLIC_URL"];
} else {

// 解决 使用 react-scripts 原始情况下 PUBLIC_URL 报错
if (!Reflect.has(process.env || {}, "PUBLIC_URL")) {
process.env.PUBLIC_URL = '';
}

Expand Down
5 changes: 4 additions & 1 deletion core/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ export interface OptionsProps {
serverNodeExternals: boolean;
serverIsChunk: boolean;
clientIsChunk: boolean;
original: boolean
original: boolean,
mini: boolean
miniServer: boolean
miniClient: boolean
}
4 changes: 4 additions & 0 deletions core/src/overrides/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface OverridesProps {
overridesClientWebpack?: (conf: webpack.Configuration, env: "development" | "production", options: any) => webpack.Configuration,
/** 服务端配置 */
overridesServerWebpack?: (conf: webpack.Configuration, env: "development" | "production", options: any) => webpack.Configuration;
/** 公共覆盖配置 */
overridesCommonWebpack?: (conf: webpack.Configuration, env: "development" | "production", options: any) => webpack.Configuration;
// 最终的配置
overridesWebpack?: WebpackConfigFunction

Expand Down Expand Up @@ -77,6 +79,8 @@ let overrides: OverridesProps = {
overridesClientWebpack: undefined,
// 自定义 server 配置设置
overridesServerWebpack: undefined,
/** 公共覆盖配置 */
overridesCommonWebpack: undefined,
// 最终自定义配置设置
overridesWebpack: undefined,
// 监听配置
Expand Down
17 changes: 1 addition & 16 deletions core/src/overrides/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,8 @@ export const restOutPut = (conf: WebpackConfiguration, options: WebpackConfigura
};
};

export const addMiniCssExtractPlugin = (conf: WebpackConfiguration): WebpackConfiguration => {
return {
...conf,
plugins: conf.plugins.concat([
// 开发状态下没有这个 plugin
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'static/css/[name].[contenthash:8].css',
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
})
]),
}
}

// loader source-map-loader

export const removeSourceMapLoader = (conf: WebpackConfiguration): WebpackConfiguration => {
return {
...conf,
Expand All @@ -164,7 +149,6 @@ export const removeSourceMapLoader = (conf: WebpackConfiguration): WebpackConfig
}
}


// node 环境 把 css 进行处理
export const restDevModuleRuleCss = (conf: WebpackConfiguration,): WebpackConfiguration => {
return {
Expand All @@ -179,6 +163,7 @@ export const restDevModuleRuleCss = (conf: WebpackConfiguration,): WebpackConfig

/**
* 1. 去除 style-loader|mini-css-extract-plugin
* 2. 修改 css-loader 配置
* */
export const getModuleCSSRules = (rules: (webpack.RuleSetRule | '...')[], shouldUseSourceMap: boolean = false) => {
const newRules: any = [];
Expand Down
121 changes: 93 additions & 28 deletions core/src/script/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
restDevModuleRuleCss,
removeSourceMapLoader
} from "../../overrides/utils"

const { choosePort } = require('react-dev-utils/WebpackDevServerUtils');
// 引入环境变量
require(`${reactScripts}/config/env`);
Expand All @@ -25,17 +26,33 @@ require(`${reactScripts}/config/env`);
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
const HOST = process.env.HOST || 'localhost';

const getWebpackConfig = (newConfig: webpack.Configuration, type: "server" | "client", overrides: OverridesProps, nodeExternals: boolean, split: boolean, env: "development" | "production", isWebpackDevServer: boolean) => {

export type GetWebpackConfig = (
newConfig: webpack.Configuration,
type: "server" | "client",
overrides: OverridesProps,
nodeExternals: boolean,
split: boolean,
env: "development" | "production",
isWebpackDevServer: boolean,
options: OptionsProps
) => webpack.Configuration


const getWebpackConfig: GetWebpackConfig = (newConfig, type, overrides, nodeExternals, split, env, isWebpackDevServer, options) => {
/** 入口 */
newConfig.entry = overrides[`${type}_path`]
/** 加载 进度条 plugin */
newConfig = getWbpackBarPlugins(newConfig, {
name: type,
})
/** 输出配置 */
const out: webpack.Configuration["output"] = {
filename: `${type}.js`,
path: overrides.output_path,
}

if (type === "server") {
/** 输出 类型 */
out.library = { type: "commonjs2" }
}

Expand All @@ -44,19 +61,21 @@ const getWebpackConfig = (newConfig: webpack.Configuration, type: "server" | "cl

const httpPath = `http://${HOST}:${PORT}`

newConfig = restOutPut(newConfig, out)

/** start 命令时候 配置前缀 为 devServer 端口 */
if (isWebpackDevServer && env === "development") {
newConfig.output.publicPath = `${httpPath}/`
out.publicPath = `${httpPath}/`
} else {
newConfig.output.publicPath = `/`
out.publicPath = `/`
}

/** 重置 输入配置 */
newConfig = restOutPut(newConfig, out)

let isCreateAsset = false;
if (isWebpackDevServer && type === "client" && env === "development") {
isCreateAsset = true
}

/** start 命令下 生成 server.js文件和 自动启动 server.js 服务 */
if (isWebpackDevServer && type === "server" && env === "development") {
newConfig.plugins.push(
new DevServerPlugins({
Expand All @@ -69,91 +88,137 @@ const getWebpackConfig = (newConfig: webpack.Configuration, type: "server" | "cl
}),
)
}

/** 重置 asset-manifest.json 文件内容 */
newConfig = restWebpackManifestPlugin(newConfig, overrides.paths, type, isCreateAsset, httpPath)

/** 清除 html 模板方面的 plugin **/
newConfig = clearHtmlTemp(newConfig)

newConfig.module.exprContextCritical = false;

const define = {
OUTPUT_PUBLIC_PATH: JSON.stringify(overrides.output_path),
KKT_PUBLIC_DIR: JSON.stringify(process.env.KKT_PUBLIC_DIR || overrides.output_path),
HOST: JSON.stringify(HOST),
PORT: JSON.stringify(PORT),
Dev_Server: JSON.stringify(isWebpackDevServer),
HOSTAPI: JSON.stringify(undefined),
"process.env.PORT": JSON.stringify(PORT),
"process.env.HOSTAPI": JSON.stringify(undefined),
"process.env.HOST": JSON.stringify(HOST)
}

if (isWebpackDevServer) {
// 代理 服务的 ip 地址
define.HOSTAPI = JSON.stringify(`http://${HOST}:${PORT}`)
define["process.env.HOSTAPI"] = JSON.stringify(`http://${HOST}:${PORT}`)
}

newConfig.plugins.push(
new webpack.DefinePlugin({
OUTPUT_PUBLIC_PATH: JSON.stringify(overrides.output_path),
HOST: JSON.stringify(HOST),
PORT: JSON.stringify(PORT),
Dev_Server: JSON.stringify(isWebpackDevServer),
"process.env.PORT": JSON.stringify(PORT || 3000),
"process.env.HOST": JSON.stringify(HOST || "localhost"),
"process.env.PUBLIC_URL": JSON.stringify(process.env.PUBLIC_URL || overrides.output_path || "")
}),
new webpack.DefinePlugin(define),
)

if (!split) {
// 代码是否进行分割
newConfig.plugins.push(new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }))
}

if (nodeExternals) {
/**
* https://www.npmjs.com/package/webpack-node-externals
* 这个库扫描node_modules文件夹中的所有 node_modules 名称,并构建一个外部函数,告诉 Webpack 不要捆绑这些模块或它们的任何子模块
* */
newConfig.externals = [webpackNodeExternals()]
}

if (type === "server") {
if (options.miniServer && type === "server") {
/** server 端 去除代码压缩 */
newConfig.optimization.minimize = false
newConfig.optimization.minimizer = []
}

if (options.miniClient && type === "client") {
/** client 端 去除代码压缩 */
newConfig.optimization.minimize = false
newConfig.optimization.minimizer = []
}

return newConfig
}

export default async (env: "development" | "production", options: OptionsProps, isWebpackDevServer: boolean = false) => {

/** 端口处理 */
const PORT = await choosePort(HOST, DEFAULT_PORT);

/** 加载自定义配置 */
const overrides = await loaderConf()

process.env.PORT = PORT || "3000"
process.env.HOST = HOST || "localhost";


const { overridesClientWebpack, overridesServerWebpack, overridesWebpack, ...rest } = overrides
const { overridesClientWebpack, overridesServerWebpack, overridesWebpack, overridesCommonWebpack, ...rest } = overrides

const configFactory = require(`${webpackConfigPath}`);

let configArr: webpack.Configuration[] = []

/**------------------------ client --------------------- */
/**------------------------ client 配置 --------------------- */
if (fs.existsSync(overrides.client_path)) {
const configClient = configFactory(env);

let newConfigClient = configClient

// 控制 client 是否使用 ssr,默认情况下使用
if (!options.original) {
newConfigClient = getWebpackConfig(configClient, "client", overrides, options.clientNodeExternals, options.clientIsChunk, env, isWebpackDevServer)

newConfigClient = getWebpackConfig(configClient, "client", overrides, options.clientNodeExternals, options.clientIsChunk, env, isWebpackDevServer, options)
}
if (isWebpackDevServer && !options.original) {
// 去除 source-map-loader
newConfigClient = removeSourceMapLoader(newConfigClient)
}
if (overridesCommonWebpack) {
newConfigClient = overridesCommonWebpack(newConfigClient, env, { ...rest, env })
}
if (overridesClientWebpack) {
newConfigClient = overridesClientWebpack(newConfigClient, env, { ...rest, env })
}
configArr.push(newConfigClient)
}

/**------------------------ server --------------------- */
/**------------------------ server 配置 --------------------- */
if (fs.existsSync(overrides.server_path)) {

const configServer = configFactory(env);
let newConfigServer = getWebpackConfig(configServer, "server", overrides, options.serverNodeExternals, options.serverIsChunk, env, isWebpackDevServer)

let newConfigServer = getWebpackConfig(configServer, "server", overrides, options.serverNodeExternals, options.serverIsChunk, env, isWebpackDevServer, options)

newConfigServer.devtool = false
newConfigServer.target = "node14"

/** server 处理 css */
newConfigServer = restDevModuleRuleCss(newConfigServer)
// 去除 source-map-loader
/** 去除 source-map-loader */
newConfigServer = removeSourceMapLoader(newConfigServer)

if (overridesCommonWebpack) {

newConfigServer = overridesCommonWebpack(newConfigServer, env, { ...rest, env })

}

if (overridesServerWebpack) {

newConfigServer = overridesServerWebpack(newConfigServer, env, { ...rest, env })

}

configArr.push(newConfigServer)
}

/**------------------------ other --------------------- */
if (overridesWebpack && typeof overridesWebpack === "function") {

configArr = overridesWebpack(configArr, env, { ...rest, env }) as webpack.Configuration[]

}

return {
Expand Down
Loading