Merge branch 'alex8088:master' into feat/dev-noElectronStart-option

This commit is contained in:
Erik Moura 2025-07-17 08:26:23 -03:00 committed by GitHub
commit 8e0c579022
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 2103 additions and 2077 deletions

View File

@ -1,2 +0,0 @@
node_modules
dist

View File

@ -1,39 +0,0 @@
module.exports = {
root: true,
env: {
commonjs: true,
es6: true,
node: true
},
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2022
},
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:prettier/recommended'
],
rules: {
'prettier/prettier': 'warn',
'no-empty': ['warn', { allowEmptyCatch: true }],
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': 'allow-with-description' }],
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-var-requires': 'off'
},
overrides: [
{
files: ['*.js'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off'
}
}
]
}

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
github: alex8088

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
node_modules
dist
.DS_Store
.eslintcache
*.log*

View File

@ -1,3 +1,48 @@
### v4.0.0 (_2025-07-06_)
- refactor!: bump required node version to 20.19+, 22.12+
- fix(deps)!: update Vite to v7 and remove cjs build
- fix: use `import type` for type-only imports
- perf: build compatibility target for Electron 36 ([#766](https://github.com/alex8088/electron-vite/pull/766))
- perf: build compatibility target for Electron 37
- chore(deps): update pnpm to v10
- chore(deps): update all non-major dependencies
- chore(deps): update lint-staged to v16
### v4.0.0-beta.0 (_2025-06-28_)
See [v4.0.0-beta.0 changelog](https://github.com/alex8088/electron-vite/blob/v4.0.0-beta.0/CHANGELOG.md)
### v3.1.0 (_2025-03-25_)
- fix(bytecodePlugin): optimize 'use strict' directive replacement ([#681](https://github.com/alex8088/electron-vite/issues/681))
- perf: build compatilibity target for Electron 35 ([#729](https://github.com/alex8088/electron-vite/pull/729))
- chore(deps): update all non-major dependencies
- chore(deps): update globals to v16
- chore(deps): update esbuild to v0.25
### v3.1.0-beta.0 (_2025-03-12_)
See [v3.1.0-beta.0 changelog](https://github.com/alex8088/electron-vite/blob/v3.1.0-beta.0/CHANGELOG.md)
### v3.0.0 (_2025-02-16_)
- feat: resolve conditions for preload
- perf: build compatilibity target for Electron 32
- perf: build compatilibity target for Electron 33 ([#651](https://github.com/alex8088/electron-vite/pull/651))
- perf: build compatilibity target for Electron 34
- chore: move to eslint flat config
- chore(deps): update all non-major dependencies
- chore(deps): update @rollup/plugin-node-resolve to v16
- chore(deps): update @rollup/plugin-typescript to v12
- chore(deps): update esbuild to v0.24
- chore(deps): update vite to v6
- chore(deps): update @type/node to v22
### v3.0.0-beta.0 (_2025-01-22_)
See [v3.0.0-beta.0 changelog](https://github.com/alex8088/electron-vite/blob/v3.0.0-beta.0/CHANGELOG.md)
### v2.3.0 (_2024-06-23_)
- feat: resolve import.meta.\[dirname|filename\] to support CommonJS format
@ -7,7 +52,7 @@
- perf: build compatilibity target for Electron 31
- perf: improve cjs shim
- chore(deps): update all non-major dependencies
- chore(deps): update @typescript-eslint/* to v7
- chore(deps): update @typescript-eslint/\* to v7
- chore(deps): update esbuild to v0.21
### v2.2.0 (_2024-04-21_)

View File

@ -24,7 +24,7 @@ if (debugIndex > 0) {
}
function run() {
import('../dist/cli.mjs')
import('../dist/cli.js')
}
run()

64
eslint.config.js Normal file
View File

@ -0,0 +1,64 @@
// ts-check
import eslint from '@eslint/js'
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
import globals from 'globals'
import tseslint from 'typescript-eslint'
export default tseslint.config(
{ ignores: ['**/node_modules', '**/dist', '**/bin'] },
eslint.configs.recommended,
tseslint.configs.recommended,
eslintPluginPrettierRecommended,
{
languageOptions: {
parser: tseslint.parser,
parserOptions: {
sourceType: 'module',
ecmaVersion: 2022
},
globals: {
...globals.es2021,
...globals.node
}
},
settings: {
node: {
version: '^20.19.0 || >=22.12.0'
}
},
rules: {
'prettier/prettier': 'warn',
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': 'allow-with-description' }],
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: true,
allowIIFEs: true
}
],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
'@typescript-eslint/no-empty-object-type': ['error', { allowInterfaces: 'always' }],
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTaggedTemplates: true,
allowTernary: true
}
]
}
},
{
files: ['*.js', '*.mjs'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off'
}
}
)

View File

@ -1,17 +1,12 @@
{
"name": "electron-vite",
"version": "2.3.0",
"version": "4.0.0",
"description": "Electron build tooling based on Vite",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
".": "./dist/index.js",
"./node": {
"types": "./node.d.ts"
},
@ -26,9 +21,9 @@
"node.d.ts"
],
"engines": {
"node": "^18.0.0 || >=20.0.0"
"node": "^20.19.0 || >=22.12.0"
},
"packageManager": "pnpm@8.6.10",
"packageManager": "pnpm@10.12.4",
"author": "Alex Wei<https://github.com/alex8088>",
"license": "MIT",
"repository": {
@ -47,7 +42,7 @@
],
"scripts": {
"format": "prettier --write .",
"lint": "eslint --ext .ts src/**",
"lint": "eslint --cache .",
"typecheck": "tsc --noEmit",
"build": "pnpm run lint && rollup -c rollup.config.ts --configPlugin typescript"
},
@ -66,7 +61,7 @@
},
"peerDependencies": {
"@swc/core": "^1.0.0",
"vite": "^4.0.0 || ^5.0.0"
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
},
"peerDependenciesMeta": {
"@swc/core": {
@ -74,32 +69,40 @@
}
},
"devDependencies": {
"@eslint/js": "^9.29.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@swc/core": "^1.6.5",
"@types/node": "^18.19.39",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"lint-staged": "^15.2.7",
"prettier": "^3.3.2",
"rollup": "^4.18.0",
"rollup-plugin-dts": "^6.1.1",
"@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-typescript": "^12.1.3",
"@swc/core": "^1.12.7",
"@types/node": "^22.15.33",
"eslint": "^9.29.0",
"eslint-config-prettier": "^10.1.5",
"eslint-plugin-prettier": "^5.5.1",
"globals": "^16.2.0",
"lint-staged": "^16.1.2",
"prettier": "^3.6.2",
"rollup": "^4.44.1",
"rollup-plugin-dts": "^6.2.1",
"rollup-plugin-rm": "^1.0.2",
"simple-git-hooks": "^2.11.1",
"tslib": "^2.6.3",
"typescript": "^5.3.3",
"vite": "^5.3.1"
"simple-git-hooks": "^2.13.0",
"tslib": "^2.8.1",
"typescript": "^5.8.3",
"typescript-eslint": "^8.35.0",
"vite": "^7.0.0"
},
"dependencies": {
"@babel/core": "^7.24.7",
"@babel/plugin-transform-arrow-functions": "^7.24.7",
"@babel/core": "^7.27.7",
"@babel/plugin-transform-arrow-functions": "^7.27.1",
"cac": "^6.7.14",
"esbuild": "^0.21.5",
"magic-string": "^0.30.10",
"picocolors": "^1.0.1"
"esbuild": "^0.25.5",
"magic-string": "^0.30.17",
"picocolors": "^1.1.1"
},
"pnpm": {
"onlyBuiltDependencies": [
"@swc/core",
"esbuild",
"simple-git-hooks"
]
}
}

3875
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -17,14 +17,8 @@ export default defineConfig([
output: [
{
dir: 'dist',
entryFileNames: '[name].cjs',
chunkFileNames: 'chunks/lib-[hash].cjs',
format: 'cjs'
},
{
dir: 'dist',
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/lib-[hash].mjs',
entryFileNames: '[name].js',
chunkFileNames: 'chunks/lib-[hash].js',
format: 'es'
}
],

View File

@ -7,7 +7,7 @@ const msgPath = process.argv[2]
const msg = fs.readFileSync(msgPath, 'utf-8').trim()
const commitRE =
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?!?: .{1,50}/
if (!commitRE.test(msg)) {
console.log()

View File

@ -1,5 +1,5 @@
import { build as viteBuild } from 'vite'
import { InlineConfig, resolveConfig } from './config'
import { type InlineConfig, resolveConfig } from './config'
/**
* Bundles the electron app for production.

View File

@ -1,7 +1,7 @@
import { cac } from 'cac'
import colors from 'picocolors'
import { LogLevel, createLogger } from 'vite'
import { InlineConfig } from './config'
import { type LogLevel, createLogger } from 'vite'
import type { InlineConfig } from './config'
import { version } from '../package.json'
const cli = cac('electron-vite')

View File

@ -343,7 +343,7 @@ async function bundleConfigFile(fileName: string, isESM: boolean): Promise<{ cod
absWorkingDir: process.cwd(),
entryPoints: [fileName],
write: false,
target: ['node18'],
target: ['node20'],
platform: 'node',
bundle: true,
format: isESM ? 'esm' : 'cjs',
@ -417,6 +417,7 @@ async function loadConfigFormBundledFile(
} finally {
try {
fs.unlinkSync(fileNameTmp)
// eslint-disable-next-line no-empty
} catch {}
}
} else {

View File

@ -69,6 +69,12 @@ export function getElectronNodeTarget(): string {
const electronVer = getElectronMajorVer()
const nodeVer = {
'37': '22.16',
'36': '22.14',
'35': '22.14',
'34': '20.18',
'33': '20.18',
'32': '20.16',
'31': '20.14',
'30': '20.11',
'29': '20.9',
@ -82,12 +88,7 @@ export function getElectronNodeTarget(): string {
'21': '16.16',
'20': '16.15',
'19': '16.14',
'18': '16.13',
'17': '16.13',
'16': '16.9',
'15': '16.5',
'14': '14.17',
'13': '14.17'
'18': '16.13'
}
if (electronVer && parseInt(electronVer) > 10) {
let target = nodeVer[electronVer]
@ -101,6 +102,12 @@ export function getElectronChromeTarget(): string {
const electronVer = getElectronMajorVer()
const chromeVer = {
'37': '138',
'36': '136',
'35': '134',
'34': '132',
'33': '130',
'32': '128',
'31': '126',
'30': '124',
'29': '122',
@ -114,12 +121,7 @@ export function getElectronChromeTarget(): string {
'21': '106',
'20': '104',
'19': '102',
'18': '100',
'17': '98',
'16': '96',
'15': '94',
'14': '93',
'13': '91'
'18': '100'
}
if (electronVer && parseInt(electronVer) > 10) {
let target = chromeVer[electronVer]

View File

@ -1,4 +1,4 @@
export { type LogLevel, createLogger, mergeConfig, splitVendorChunkPlugin, splitVendorChunk } from 'vite'
export { type LogLevel, createLogger, mergeConfig } from 'vite'
export * from './config'
export { createServer } from './server'
export { build } from './build'

View File

@ -115,7 +115,7 @@ export default function assetPlugin(): Plugin {
const hash = this.emitFile({
type: 'asset',
name: path.basename(file),
source
source: source as unknown as Uint8Array
})
referenceId = `__VITE_NODE_ASSET__${hash}__`
assetCache.set(file, referenceId)

View File

@ -310,7 +310,7 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
const chunkFileName = path.resolve(outDir, name)
if (bytecodeChunks.includes(name)) {
const bytecodeBuffer = await compileToBytecode(_code)
fs.writeFileSync(path.resolve(outDir, name + 'c'), bytecodeBuffer)
fs.writeFileSync(path.resolve(outDir, name + 'c'), bytecodeBuffer as unknown as Uint8Array)
if (chunk.isEntry) {
if (!removeBundleJS) {
keepBundle(chunkFileName)
@ -344,7 +344,9 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
}
}
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName)
_code = hasBytecodeMoudle ? _code.replace(useStrict, `${useStrict}\n${bytecodeLoaderBlock}`) : _code
_code = hasBytecodeMoudle
? _code.replace(/("use strict";)|('use strict';)/, `${useStrict}\n${bytecodeLoaderBlock}`)
: _code
}
fs.writeFileSync(chunkFileName, _code)
}

View File

@ -198,6 +198,12 @@ export function electronPreloadVitePlugin(options?: ElectronPluginOptions): Plug
const format = pkg.type && pkg.type === 'module' && supportESM() ? 'es' : 'cjs'
const defaultConfig = {
ssr: {
resolve: {
conditions: ['module', 'browser', 'development|production'],
mainFields: ['browser', 'module', 'jsnext:main', 'jsnext']
}
},
build: {
outDir: path.resolve(root, 'out', 'preload'),
target: nodeTarget,
@ -272,7 +278,8 @@ export function electronPreloadVitePlugin(options?: ElectronPluginOptions): Plug
// enable ssr build
config.build.ssr = true
config.build.ssrEmitAssets = true
config.ssr = { ...config.ssr, ...{ noExternal: true } }
config.ssr = mergeConfig(defaultConfig.ssr, config.ssr || {})
config.ssr.noExternal = true
}
},
{

View File

@ -29,7 +29,10 @@ export function parseRequest(id: string): Record<string, string> | null {
}
export function getHash(text: Buffer | string): string {
return createHash('sha256').update(text).digest('hex').substring(0, 8)
return createHash('sha256')
.update(text as unknown as Uint8Array)
.digest('hex')
.substring(0, 8)
}
export function toRelativePath(filename: string, importer: string): string {

View File

@ -1,13 +1,13 @@
{
"compilerOptions": {
"target": "ES2022",
"target": "ES2023",
"module": "ESNext",
"lib": ["ESNext"],
"sourceMap": false,
"strict": true,
"allowJs": true,
"esModuleInterop": true,
"moduleResolution": "Node",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,