feat: add --rendererOnly flag to dev command
This commit is contained in:
parent
a736af835e
commit
f443c18056
|
@ -60,7 +60,8 @@ cli
|
|||
.alias('dev')
|
||||
.option('-w, --watch', `[boolean] rebuilds when main process or preload script modules have changed on disk`)
|
||||
.option('--remoteDebuggingPort <port>', `[string] port for remote debugging`)
|
||||
.action(async (root: string, options: { remoteDebuggingPort?: string } & GlobalCLIOptions) => {
|
||||
.option('--rendererOnly', `[boolean] only dev server for the renderer`)
|
||||
.action(async (root: string, options: { remoteDebuggingPort?: string; rendererOnly: boolean } & GlobalCLIOptions) => {
|
||||
if (options.remoteDebuggingPort) {
|
||||
process.env.REMOTE_DEBUGGING_PORT = options.remoteDebuggingPort
|
||||
}
|
||||
|
@ -69,7 +70,7 @@ cli
|
|||
const inlineConfig = createInlineConfig(root, options)
|
||||
|
||||
try {
|
||||
await createServer(inlineConfig)
|
||||
await createServer(inlineConfig, { rendererOnly: options.rendererOnly })
|
||||
} catch (e) {
|
||||
const error = e as Error
|
||||
createLogger(options.logLevel).error(
|
||||
|
|
|
@ -12,7 +12,10 @@ import { type InlineConfig, resolveConfig } from './config'
|
|||
import { resolveHostname } from './utils'
|
||||
import { startElectron } from './electron'
|
||||
|
||||
export async function createServer(inlineConfig: InlineConfig = {}): Promise<void> {
|
||||
export async function createServer(
|
||||
inlineConfig: InlineConfig = {},
|
||||
options: { rendererOnly?: boolean }
|
||||
): Promise<void> {
|
||||
process.env.NODE_ENV_ELECTRON_VITE = 'development'
|
||||
const config = await resolveConfig(inlineConfig, 'serve', 'development')
|
||||
if (config.config) {
|
||||
|
@ -22,7 +25,7 @@ export async function createServer(inlineConfig: InlineConfig = {}): Promise<voi
|
|||
let ps: ChildProcessWithoutNullStreams | undefined
|
||||
|
||||
const mainViteConfig = config.config?.main
|
||||
if (mainViteConfig) {
|
||||
if (mainViteConfig && !options.rendererOnly) {
|
||||
const watchHook = (): void => {
|
||||
logger.info(colors.green(`\nrebuild the electron main process successfully`))
|
||||
|
||||
|
@ -43,7 +46,7 @@ export async function createServer(inlineConfig: InlineConfig = {}): Promise<voi
|
|||
}
|
||||
|
||||
const preloadViteConfig = config.config?.preload
|
||||
if (preloadViteConfig) {
|
||||
if (preloadViteConfig && !options.rendererOnly) {
|
||||
logger.info(colors.gray(`\n-----\n`))
|
||||
|
||||
const watchHook = (): void => {
|
||||
|
@ -61,6 +64,14 @@ export async function createServer(inlineConfig: InlineConfig = {}): Promise<voi
|
|||
logger.info(colors.green(`\nbuild the electron preload files successfully`))
|
||||
}
|
||||
|
||||
if (options.rendererOnly) {
|
||||
logger.warn(
|
||||
`\n${colors.yellow(colors.bold('warn'))}:${colors.yellow(
|
||||
' you have skipped the main process and preload scripts building'
|
||||
)}`
|
||||
)
|
||||
}
|
||||
|
||||
const rendererViteConfig = config.config?.renderer
|
||||
if (rendererViteConfig) {
|
||||
logger.info(colors.gray(`\n-----\n`))
|
||||
|
@ -83,7 +94,7 @@ export async function createServer(inlineConfig: InlineConfig = {}): Promise<voi
|
|||
const slogger = server.config.logger
|
||||
|
||||
slogger.info(colors.green(`dev server running for the electron renderer process at:\n`), {
|
||||
clear: !slogger.hasWarned
|
||||
clear: !slogger.hasWarned && !options.rendererOnly
|
||||
})
|
||||
|
||||
server.printUrls()
|
||||
|
|
Loading…
Reference in a new issue