refactor: inline bytecode build plugin name

This commit is contained in:
alex8088 2026-10-11 00:37:36 +08:00
parent 6fc103eb5b
commit 0655933704
3 changed files with 2 additions and 5 deletions

View File

@ -1,7 +1,6 @@
import { build as viteBuild, mergeConfig } from 'vite' import { build as viteBuild, mergeConfig } from 'vite'
import { type InlineConfig, type MainViteConfig, type PreloadViteConfig, resolveConfig } from './config' import { type InlineConfig, type MainViteConfig, type PreloadViteConfig, resolveConfig } from './config'
import { BytecodeCompiler } from './bytecodeCompiler' import { BytecodeCompiler } from './bytecodeCompiler'
import { BYTECODE_BUILD_PLUGIN_NAME } from './constants'
import { asyncFlatten } from './utils' import { asyncFlatten } from './utils'
async function usesBytecode(config?: MainViteConfig | PreloadViteConfig): Promise<boolean> { async function usesBytecode(config?: MainViteConfig | PreloadViteConfig): Promise<boolean> {
@ -20,7 +19,7 @@ export async function build(inlineConfig: InlineConfig = {}): Promise<void> {
const bytecodeCompiler = new BytecodeCompiler() const bytecodeCompiler = new BytecodeCompiler()
const config = await resolveConfig( const config = await resolveConfig(
mergeConfig(inlineConfig, { mergeConfig(inlineConfig, {
plugins: [{ name: BYTECODE_BUILD_PLUGIN_NAME, api: { compiler: bytecodeCompiler } }] plugins: [{ name: 'vite:electron-bytecode-build', api: { compiler: bytecodeCompiler } }]
}), }),
'build', 'build',
'production' 'production'

View File

@ -1 +0,0 @@
export const BYTECODE_BUILD_PLUGIN_NAME = 'vite:electron-bytecode-build'

View File

@ -6,12 +6,11 @@ import * as babel from '@babel/core'
import MagicString from 'magic-string' import MagicString from 'magic-string'
import { toRelativePath } from '../utils' import { toRelativePath } from '../utils'
import type { BytecodeCompiler, BytecodeTarget } from '../bytecodeCompiler' import type { BytecodeCompiler, BytecodeTarget } from '../bytecodeCompiler'
import { BYTECODE_BUILD_PLUGIN_NAME } from '../constants'
// Inspired by https://github.com/bytenode/bytenode // Inspired by https://github.com/bytenode/bytenode
function getBytecodeCompiler(plugins: readonly Plugin[]): BytecodeCompiler | undefined { function getBytecodeCompiler(plugins: readonly Plugin[]): BytecodeCompiler | undefined {
const plugin = plugins.find(plugin => plugin.name === BYTECODE_BUILD_PLUGIN_NAME) const plugin = plugins.find(plugin => plugin.name === 'vite:electron-bytecode-build')
return (plugin?.api as { compiler?: BytecodeCompiler } | undefined)?.compiler return (plugin?.api as { compiler?: BytecodeCompiler } | undefined)?.compiler
} }