Skip to content

Commit

Permalink
feat(@kkt/ssr):命令行新增 target 属性
Browse files Browse the repository at this point in the history
  • Loading branch information
SunLxy committed Apr 6, 2022
1 parent d52fce5 commit 2634ba7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function help() {
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(' --target ', 'clent or server or all.');

console.log('\n Example:\n');
console.log(' $ \x1b[35mkkt-ssr\x1b[0m build');
Expand Down Expand Up @@ -51,6 +52,7 @@ interface SSRNCCArgs extends BuildArgs {
"original"?: boolean,
"m"?: boolean;
"minify"?: boolean,
"target"?: "client" | "server" | "all"
}

(async () => {
Expand Down Expand Up @@ -83,6 +85,8 @@ interface SSRNCCArgs extends BuildArgs {
const miniServer = getBoolean(argvs["s-m"], argvs["s-minify"], mini)
const miniClient = getBoolean(argvs["c-m"], argvs["c-minify"], mini)

const target = argvs["target"] || "all"

const options: OptionsProps = {
clientNodeExternals,
serverNodeExternals,
Expand All @@ -91,7 +95,8 @@ interface SSRNCCArgs extends BuildArgs {
original,
mini,
miniServer,
miniClient
miniClient,
target
}
// 解决 使用 react-scripts 原始情况下 PUBLIC_URL 报错
if (!Reflect.has(process.env || {}, "PUBLIC_URL")) {
Expand Down
3 changes: 2 additions & 1 deletion core/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ export interface OptionsProps {
/** server 是否压缩代码 **/
miniServer: boolean
/** client 是否压缩代码 **/
miniClient: boolean
miniClient: boolean,
target: "client" | "server" | "all"
}
4 changes: 2 additions & 2 deletions core/src/utils/getWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default async (env: "development" | "production", options: OptionsProps,)
let configArr: webpack.Configuration[] = []

/**------------------------ client 配置 --------------------- */
if (fs.existsSync(overrides.client_path)) {
if (fs.existsSync(overrides.client_path) && ["all", "client"].includes(options.target)) {
const configClient = configFactory(env);

let newConfigClient = configClient
Expand All @@ -65,7 +65,7 @@ export default async (env: "development" | "production", options: OptionsProps,)
}

/**------------------------ server 配置 --------------------- */
if (fs.existsSync(overrides.server_path) && overrides.isUseServerConfig) {
if (fs.existsSync(overrides.server_path) && overrides.isUseServerConfig && ["all", "server"].includes(options.target)) {

const configServer = configFactory(env);

Expand Down

0 comments on commit 2634ba7

Please sign in to comment.