mirror of
https://github.com/alex8088/electron-vite.git
synced 2026-07-14 19:21:06 +08:00
Compare commits
4 Commits
6170705eae
...
ff23f7d44d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff23f7d44d | ||
|
|
a48e12a9df | ||
|
|
1abedce6c2 | ||
|
|
c2c655367f |
@ -88,6 +88,7 @@
|
||||
"prettier": "^3.1.0",
|
||||
"rollup": "^4.6.1",
|
||||
"rollup-plugin-dts": "^6.1.0",
|
||||
"rollup-plugin-rm": "^1.0.2",
|
||||
"simple-git-hooks": "^2.9.0",
|
||||
"tslib": "^2.6.2",
|
||||
"typescript": "^5.3.3",
|
||||
|
||||
11
pnpm-lock.yaml
generated
11
pnpm-lock.yaml
generated
@ -67,6 +67,9 @@ devDependencies:
|
||||
rollup-plugin-dts:
|
||||
specifier: ^6.1.0
|
||||
version: 6.1.0(rollup@4.6.1)(typescript@5.3.3)
|
||||
rollup-plugin-rm:
|
||||
specifier: ^1.0.2
|
||||
version: 1.0.2(rollup@4.6.1)
|
||||
simple-git-hooks:
|
||||
specifier: ^2.9.0
|
||||
version: 2.9.0
|
||||
@ -2216,6 +2219,14 @@ packages:
|
||||
'@babel/code-frame': 7.23.5
|
||||
dev: true
|
||||
|
||||
/rollup-plugin-rm@1.0.2(rollup@4.6.1):
|
||||
resolution: {integrity: sha512-RSUFFibfkCvIeQrTg7TLs59m6S//qcmDfTNqgQ2Pd9BlABd/q74ymmg5936h0vfnjrFHhale/+f+efgp7deLEg==}
|
||||
peerDependencies:
|
||||
rollup: ^3.0.0||^4.0.0
|
||||
dependencies:
|
||||
rollup: 4.6.1
|
||||
dev: true
|
||||
|
||||
/rollup@4.6.1:
|
||||
resolution: {integrity: sha512-jZHaZotEHQaHLgKr8JnQiDT1rmatjgKlMekyksz+yk9jt/8z9quNjnKNRoaM0wd9DC2QKXjmWWuDYtM3jfF8pQ==}
|
||||
engines: {node: '>=18.0.0', npm: '>=8.0.0'}
|
||||
|
||||
@ -1,33 +1,16 @@
|
||||
import { createRequire } from 'node:module'
|
||||
import fs from 'node:fs/promises'
|
||||
import { type Plugin, defineConfig } from 'rollup'
|
||||
import { defineConfig } from 'rollup'
|
||||
import ts from '@rollup/plugin-typescript'
|
||||
import resolve from '@rollup/plugin-node-resolve'
|
||||
import json from '@rollup/plugin-json'
|
||||
import dts from 'rollup-plugin-dts'
|
||||
import rm from 'rollup-plugin-rm'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const pkg = require('./package.json')
|
||||
|
||||
const external = ['esbuild', ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]
|
||||
|
||||
function clean(when: 'buildStart' | 'buildEnd', target: string): Plugin {
|
||||
const _clean = async (target): Promise<void> => {
|
||||
await fs.rm(target, { recursive: true, force: true }).catch(() => {})
|
||||
}
|
||||
return {
|
||||
name: 'clean',
|
||||
buildStart: async (): Promise<void> => {
|
||||
if (when !== 'buildStart') return
|
||||
await _clean(target)
|
||||
},
|
||||
buildEnd: async (): Promise<void> => {
|
||||
if (when !== 'buildEnd') return
|
||||
await _clean(target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig([
|
||||
{
|
||||
input: ['src/index.ts', 'src/cli.ts'],
|
||||
@ -47,7 +30,7 @@ export default defineConfig([
|
||||
],
|
||||
external,
|
||||
plugins: [
|
||||
clean('buildStart', 'dist'),
|
||||
rm('dist', 'buildStart'),
|
||||
json(),
|
||||
ts({ compilerOptions: { rootDir: 'src', declaration: true, declarationDir: 'dist/types' } }),
|
||||
resolve()
|
||||
@ -59,6 +42,6 @@ export default defineConfig([
|
||||
{
|
||||
input: 'dist/types/index.d.ts',
|
||||
output: [{ file: pkg.types, format: 'es' }],
|
||||
plugins: [dts(), clean('buildEnd', 'dist/types')]
|
||||
plugins: [dts(), rm('dist/types', 'buildEnd')]
|
||||
}
|
||||
])
|
||||
|
||||
@ -5,7 +5,7 @@ import { createRequire } from 'node:module'
|
||||
import colors from 'picocolors'
|
||||
import {
|
||||
type UserConfig as ViteConfig,
|
||||
type UserConfigExport as UserViteConfigExport,
|
||||
type UserConfigExport as ViteConfigExport,
|
||||
type ConfigEnv,
|
||||
type Plugin,
|
||||
type LogLevel,
|
||||
@ -46,25 +46,25 @@ export interface UserConfig {
|
||||
preload?: ViteConfig & { configFile?: string | false }
|
||||
}
|
||||
|
||||
export interface UserConfigSchema {
|
||||
export interface ElectronViteConfig {
|
||||
/**
|
||||
* Vite config options for electron main process
|
||||
*
|
||||
* https://vitejs.dev/config/
|
||||
*/
|
||||
main?: UserViteConfigExport
|
||||
main?: ViteConfigExport
|
||||
/**
|
||||
* Vite config options for electron renderer process
|
||||
*
|
||||
* https://vitejs.dev/config/
|
||||
*/
|
||||
renderer?: UserViteConfigExport
|
||||
renderer?: ViteConfigExport
|
||||
/**
|
||||
* Vite config options for electron preload files
|
||||
*
|
||||
* https://vitejs.dev/config/
|
||||
*/
|
||||
preload?: UserViteConfigExport
|
||||
preload?: ViteConfigExport
|
||||
}
|
||||
|
||||
export type InlineConfig = Omit<ViteConfig, 'base'> & {
|
||||
@ -73,16 +73,28 @@ export type InlineConfig = Omit<ViteConfig, 'base'> & {
|
||||
ignoreConfigWarning?: boolean
|
||||
}
|
||||
|
||||
export type UserConfigFn = (env: ConfigEnv) => UserConfigSchema | Promise<UserConfigSchema>
|
||||
export type UserConfigExport = UserConfigSchema | Promise<UserConfigSchema> | UserConfigFn
|
||||
export type ElectronViteConfigFnObject = (env: ConfigEnv) => ElectronViteConfig
|
||||
export type ElectronViteConfigFnPromise = (env: ConfigEnv) => Promise<ElectronViteConfig>
|
||||
export type ElectronViteConfigFn = (env: ConfigEnv) => ElectronViteConfig | Promise<ElectronViteConfig>
|
||||
|
||||
export type ElectronViteConfigExport =
|
||||
| ElectronViteConfig
|
||||
| Promise<ElectronViteConfig>
|
||||
| ElectronViteConfigFnObject
|
||||
| ElectronViteConfigFnPromise
|
||||
| ElectronViteConfigFn
|
||||
|
||||
/**
|
||||
* Type helper to make it easier to use `electron.vite.config.*`
|
||||
* accepts a direct {@link UserConfig} object, or a function that returns it.
|
||||
* accepts a direct {@link ElectronViteConfig} object, or a function that returns it.
|
||||
* The function receives a object that exposes two properties:
|
||||
* `command` (either `'build'` or `'serve'`), and `mode`.
|
||||
*/
|
||||
export function defineConfig(config: UserConfigExport): UserConfigExport {
|
||||
export function defineConfig(config: ElectronViteConfig): ElectronViteConfig
|
||||
export function defineConfig(config: Promise<ElectronViteConfig>): Promise<ElectronViteConfig>
|
||||
export function defineConfig(config: ElectronViteConfigFnObject): ElectronViteConfigFnObject
|
||||
export function defineConfig(config: ElectronViteConfigExport): ElectronViteConfigExport
|
||||
export function defineConfig(config: ElectronViteConfigExport): ElectronViteConfigExport {
|
||||
return config
|
||||
}
|
||||
|
||||
@ -390,7 +402,7 @@ async function loadConfigFormBundledFile(
|
||||
configFile: string,
|
||||
bundledCode: string,
|
||||
isESM: boolean
|
||||
): Promise<UserConfigExport> {
|
||||
): Promise<ElectronViteConfigExport> {
|
||||
if (isESM) {
|
||||
const fileNameTmp = path.resolve(configRoot, `${CONFIG_FILE_NAME}.${Date.now()}.mjs`)
|
||||
fs.writeFileSync(fileNameTmp, bundledCode)
|
||||
|
||||
@ -2,7 +2,7 @@ import type { ChildProcess } from 'node:child_process'
|
||||
import {
|
||||
type UserConfig as ViteConfig,
|
||||
type ViteDevServer,
|
||||
createServer as ViteCreateServer,
|
||||
createServer as viteCreateServer,
|
||||
build as viteBuild,
|
||||
createLogger,
|
||||
mergeConfig
|
||||
@ -80,7 +80,7 @@ export async function createServer(
|
||||
if (rendererViteConfig) {
|
||||
logger.info(colors.gray(`\n-----\n`))
|
||||
|
||||
server = await ViteCreateServer(rendererViteConfig)
|
||||
server = await viteCreateServer(rendererViteConfig)
|
||||
|
||||
if (!server.httpServer) {
|
||||
throw new Error('HTTP server not available')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user