mirror of
https://github.com/alex8088/electron-vite.git
synced 2025-04-06 04:05:44 +08:00
Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1b411d3633 | ||
|
b56d3c2d21 | ||
|
f2eff25268 | ||
|
2d8e513e07 | ||
|
d8063320dc | ||
|
f33c5b2abe | ||
|
e91e70c105 | ||
|
ea144aef19 | ||
|
987c55ee8b | ||
|
8064bd81ff | ||
|
6e8572d9b7 | ||
|
4b47ef0bd4 | ||
|
5a5af050b2 | ||
|
96ae3c5cd9 | ||
|
79ac91dee2 | ||
|
1599d730f6 | ||
|
3c6e08b2f2 | ||
|
dfe6a3e3f8 | ||
|
6c01417909 | ||
|
5ffd49eddc | ||
|
bf1220875f |
@ -1,2 +0,0 @@
|
||||
node_modules
|
||||
dist
|
@ -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'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
||||
node_modules
|
||||
dist
|
||||
.DS_Store
|
||||
|
||||
.eslintcache
|
||||
*.log*
|
||||
|
32
CHANGELOG.md
32
CHANGELOG.md
@ -1,3 +1,33 @@
|
||||
### 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 +37,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_)
|
||||
|
42
eslint.config.js
Normal file
42
eslint.config.js
Normal file
@ -0,0 +1,42 @@
|
||||
// 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
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
'prettier/prettier': 'warn',
|
||||
'@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'
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['*.js', '*.mjs'],
|
||||
rules: {
|
||||
'@typescript-eslint/explicit-function-return-type': 'off'
|
||||
}
|
||||
}
|
||||
)
|
47
package.json
47
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "electron-vite",
|
||||
"version": "2.3.0",
|
||||
"version": "3.1.0",
|
||||
"description": "Electron build tooling based on Vite",
|
||||
"type": "module",
|
||||
"main": "dist/index.cjs",
|
||||
@ -47,7 +47,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 +66,7 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@swc/core": "^1.0.0",
|
||||
"vite": "^4.0.0 || ^5.0.0"
|
||||
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@swc/core": {
|
||||
@ -74,32 +74,33 @@
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.22.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-node-resolve": "^16.0.1",
|
||||
"@rollup/plugin-typescript": "^12.1.2",
|
||||
"@swc/core": "^1.11.9",
|
||||
"@types/node": "^22.13.10",
|
||||
"eslint": "^9.22.0",
|
||||
"eslint-config-prettier": "^10.1.1",
|
||||
"eslint-plugin-prettier": "^5.2.3",
|
||||
"globals": "^16.0.0",
|
||||
"lint-staged": "^15.4.3",
|
||||
"prettier": "^3.5.3",
|
||||
"rollup": "^4.35.0",
|
||||
"rollup-plugin-dts": "^6.1.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"
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.7.3",
|
||||
"typescript-eslint": "^8.26.1",
|
||||
"vite": "^6.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.24.7",
|
||||
"@babel/plugin-transform-arrow-functions": "^7.24.7",
|
||||
"@babel/core": "^7.26.10",
|
||||
"@babel/plugin-transform-arrow-functions": "^7.25.9",
|
||||
"cac": "^6.7.14",
|
||||
"esbuild": "^0.21.5",
|
||||
"magic-string": "^0.30.10",
|
||||
"picocolors": "^1.0.1"
|
||||
"esbuild": "^0.25.1",
|
||||
"magic-string": "^0.30.17",
|
||||
"picocolors": "^1.1.1"
|
||||
}
|
||||
}
|
||||
|
2023
pnpm-lock.yaml
generated
2023
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -417,6 +417,7 @@ async function loadConfigFormBundledFile(
|
||||
} finally {
|
||||
try {
|
||||
fs.unlinkSync(fileNameTmp)
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch {}
|
||||
}
|
||||
} else {
|
||||
|
@ -69,6 +69,10 @@ export function getElectronNodeTarget(): string {
|
||||
const electronVer = getElectronMajorVer()
|
||||
|
||||
const nodeVer = {
|
||||
'35': '22.14',
|
||||
'34': '20.18',
|
||||
'33': '20.18',
|
||||
'32': '20.16',
|
||||
'31': '20.14',
|
||||
'30': '20.11',
|
||||
'29': '20.9',
|
||||
@ -85,9 +89,7 @@ export function getElectronNodeTarget(): string {
|
||||
'18': '16.13',
|
||||
'17': '16.13',
|
||||
'16': '16.9',
|
||||
'15': '16.5',
|
||||
'14': '14.17',
|
||||
'13': '14.17'
|
||||
'15': '16.5'
|
||||
}
|
||||
if (electronVer && parseInt(electronVer) > 10) {
|
||||
let target = nodeVer[electronVer]
|
||||
@ -101,6 +103,10 @@ export function getElectronChromeTarget(): string {
|
||||
const electronVer = getElectronMajorVer()
|
||||
|
||||
const chromeVer = {
|
||||
'35': '134',
|
||||
'34': '132',
|
||||
'33': '130',
|
||||
'32': '128',
|
||||
'31': '126',
|
||||
'30': '124',
|
||||
'29': '122',
|
||||
@ -117,9 +123,7 @@ export function getElectronChromeTarget(): string {
|
||||
'18': '100',
|
||||
'17': '98',
|
||||
'16': '96',
|
||||
'15': '94',
|
||||
'14': '93',
|
||||
'13': '91'
|
||||
'15': '94'
|
||||
}
|
||||
if (electronVer && parseInt(electronVer) > 10) {
|
||||
let target = chromeVer[electronVer]
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user