Skip to content

Commit

Permalink
fix(@kkt/ssr):优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
SunLxy committed Apr 7, 2022
1 parent 50c4b74 commit 5be472b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions core/src/overrides/overridesWebpackDevServerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import { reactDevUtils } from "./pathUtils"
import webpack from "webpack"
const WebpackDevServerUtilsPath = `${reactDevUtils}/WebpackDevServerUtils`
import chalk from 'chalk';

const WebpackDevServerUtilsPath = `${reactDevUtils}/WebpackDevServerUtils`
const WebpackDevServerUtils = require(`${WebpackDevServerUtilsPath}`)
const clearConsole = require(`${reactDevUtils}/clearConsole`)
const formatWebpackMessages = require(`${reactDevUtils}/formatWebpackMessages`)
const chalk = require('chalk');

export interface Urls {
lanUrlForConfig?: string | undefined;
Expand Down
6 changes: 3 additions & 3 deletions core/src/utils/ProcessingConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CreateTemporaryAsset from "./plugins/CreateTemporaryAsset"
import { restOutPut } from "./output"
import { getWbpackBarPlugins, restWebpackManifestPlugin, clearHtmlTemp, addServerPlugins, AddDefinePlugin } from "./plugins"

export type GetWebpackConfig = (
export type ProcessingConfigProps = (
newConfig: webpack.Configuration,
type: "server" | "client",
overrides: OverridesProps,
Expand All @@ -16,7 +16,7 @@ export type GetWebpackConfig = (
) => webpack.Configuration


const getWebpackConfig: GetWebpackConfig = (newConfig, type, overrides, nodeExternals, split, options) => {
const processingConfig: ProcessingConfigProps = (newConfig, type, overrides, nodeExternals, split, options) => {
const isDev = process.env.NODE_ENV === "development"
/** 入口 */
newConfig.entry = overrides[`${type}_path`]
Expand Down Expand Up @@ -100,4 +100,4 @@ const getWebpackConfig: GetWebpackConfig = (newConfig, type, overrides, nodeExte
return newConfig
}

export default getWebpackConfig
export default processingConfig
6 changes: 3 additions & 3 deletions core/src/utils/getWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from 'fs';
import { OptionsProps } from "../interface"
import { loaderConf } from "../overrides"
import { restDevModuleRuleCss, removeSourceMapLoader } from "./module"
import getWebpackConfig from "./ProcessingConfig"
import processingConfig from "./ProcessingConfig"

const { choosePort } = require('react-dev-utils/WebpackDevServerUtils');

Expand Down Expand Up @@ -49,7 +49,7 @@ export default async (env: "development" | "production", options: OptionsProps,)
// 控制 client 是否使用 ssr,默认情况下使用
if (!original) {

newConfigClient = getWebpackConfig(configClient, "client", overrides, options.clientNodeExternals, options.clientIsChunk, options)
newConfigClient = processingConfig(configClient, "client", overrides, options.clientNodeExternals, options.clientIsChunk, options)
}
if (!original) {
// 去除 source-map-loader
Expand All @@ -69,7 +69,7 @@ export default async (env: "development" | "production", options: OptionsProps,)

const configServer = configFactory(env);

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

newConfigServer.devtool = false
newConfigServer.target = "node14"
Expand Down
2 changes: 2 additions & 0 deletions core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export * from "./module"
export * from "./plugins"
export * from "./output"

export { default as getWebpackConfig } from "./getWebpackConfig"
export { default as processingConfig } from "./ProcessingConfig"
type BoolenValue = boolean | undefined | "false" | "true"

export const getBoolean = (one: BoolenValue, two: BoolenValue, defaultValue: boolean = false) => {
Expand Down

0 comments on commit 5be472b

Please sign in to comment.