mirror of
https://github.com/alex8088/electron-vite.git
synced 2025-08-17 01:30:08 +08:00
Merge branch 'alex8088:master' into feat/dev-noElectronStart-option
This commit is contained in:
commit
8e0c579022
@ -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'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
github: alex8088
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.eslintcache
|
||||||
*.log*
|
*.log*
|
||||||
|
47
CHANGELOG.md
47
CHANGELOG.md
@ -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_)
|
### v2.3.0 (_2024-06-23_)
|
||||||
|
|
||||||
- feat: resolve import.meta.\[dirname|filename\] to support CommonJS format
|
- feat: resolve import.meta.\[dirname|filename\] to support CommonJS format
|
||||||
@ -7,7 +52,7 @@
|
|||||||
- perf: build compatilibity target for Electron 31
|
- perf: build compatilibity target for Electron 31
|
||||||
- perf: improve cjs shim
|
- perf: improve cjs shim
|
||||||
- chore(deps): update all non-major dependencies
|
- 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
|
- chore(deps): update esbuild to v0.21
|
||||||
|
|
||||||
### v2.2.0 (_2024-04-21_)
|
### v2.2.0 (_2024-04-21_)
|
||||||
|
@ -24,7 +24,7 @@ if (debugIndex > 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
import('../dist/cli.mjs')
|
import('../dist/cli.js')
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
64
eslint.config.js
Normal file
64
eslint.config.js
Normal 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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
73
package.json
73
package.json
@ -1,17 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "electron-vite",
|
"name": "electron-vite",
|
||||||
"version": "2.3.0",
|
"version": "4.0.0",
|
||||||
"description": "Electron build tooling based on Vite",
|
"description": "Electron build tooling based on Vite",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.cjs",
|
"main": "./dist/index.js",
|
||||||
"module": "dist/index.mjs",
|
"types": "./dist/index.d.ts",
|
||||||
"types": "dist/index.d.ts",
|
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
|
||||||
"import": "./dist/index.mjs",
|
|
||||||
"require": "./dist/index.cjs"
|
|
||||||
},
|
|
||||||
"./node": {
|
"./node": {
|
||||||
"types": "./node.d.ts"
|
"types": "./node.d.ts"
|
||||||
},
|
},
|
||||||
@ -26,9 +21,9 @@
|
|||||||
"node.d.ts"
|
"node.d.ts"
|
||||||
],
|
],
|
||||||
"engines": {
|
"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>",
|
"author": "Alex Wei<https://github.com/alex8088>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -47,7 +42,7 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"lint": "eslint --ext .ts src/**",
|
"lint": "eslint --cache .",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"build": "pnpm run lint && rollup -c rollup.config.ts --configPlugin typescript"
|
"build": "pnpm run lint && rollup -c rollup.config.ts --configPlugin typescript"
|
||||||
},
|
},
|
||||||
@ -66,7 +61,7 @@
|
|||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@swc/core": "^1.0.0",
|
"@swc/core": "^1.0.0",
|
||||||
"vite": "^4.0.0 || ^5.0.0"
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@swc/core": {
|
"@swc/core": {
|
||||||
@ -74,32 +69,40 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.29.0",
|
||||||
"@rollup/plugin-json": "^6.1.0",
|
"@rollup/plugin-json": "^6.1.0",
|
||||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||||
"@rollup/plugin-typescript": "^11.1.6",
|
"@rollup/plugin-typescript": "^12.1.3",
|
||||||
"@swc/core": "^1.6.5",
|
"@swc/core": "^1.12.7",
|
||||||
"@types/node": "^18.19.39",
|
"@types/node": "^22.15.33",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.13.1",
|
"eslint": "^9.29.0",
|
||||||
"@typescript-eslint/parser": "^7.13.1",
|
"eslint-config-prettier": "^10.1.5",
|
||||||
"eslint": "^8.57.0",
|
"eslint-plugin-prettier": "^5.5.1",
|
||||||
"eslint-config-prettier": "^9.1.0",
|
"globals": "^16.2.0",
|
||||||
"eslint-plugin-prettier": "^5.1.3",
|
"lint-staged": "^16.1.2",
|
||||||
"lint-staged": "^15.2.7",
|
"prettier": "^3.6.2",
|
||||||
"prettier": "^3.3.2",
|
"rollup": "^4.44.1",
|
||||||
"rollup": "^4.18.0",
|
"rollup-plugin-dts": "^6.2.1",
|
||||||
"rollup-plugin-dts": "^6.1.1",
|
|
||||||
"rollup-plugin-rm": "^1.0.2",
|
"rollup-plugin-rm": "^1.0.2",
|
||||||
"simple-git-hooks": "^2.11.1",
|
"simple-git-hooks": "^2.13.0",
|
||||||
"tslib": "^2.6.3",
|
"tslib": "^2.8.1",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.8.3",
|
||||||
"vite": "^5.3.1"
|
"typescript-eslint": "^8.35.0",
|
||||||
|
"vite": "^7.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.24.7",
|
"@babel/core": "^7.27.7",
|
||||||
"@babel/plugin-transform-arrow-functions": "^7.24.7",
|
"@babel/plugin-transform-arrow-functions": "^7.27.1",
|
||||||
"cac": "^6.7.14",
|
"cac": "^6.7.14",
|
||||||
"esbuild": "^0.21.5",
|
"esbuild": "^0.25.5",
|
||||||
"magic-string": "^0.30.10",
|
"magic-string": "^0.30.17",
|
||||||
"picocolors": "^1.0.1"
|
"picocolors": "^1.1.1"
|
||||||
|
},
|
||||||
|
"pnpm": {
|
||||||
|
"onlyBuiltDependencies": [
|
||||||
|
"@swc/core",
|
||||||
|
"esbuild",
|
||||||
|
"simple-git-hooks"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3875
pnpm-lock.yaml
generated
3875
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -17,14 +17,8 @@ export default defineConfig([
|
|||||||
output: [
|
output: [
|
||||||
{
|
{
|
||||||
dir: 'dist',
|
dir: 'dist',
|
||||||
entryFileNames: '[name].cjs',
|
entryFileNames: '[name].js',
|
||||||
chunkFileNames: 'chunks/lib-[hash].cjs',
|
chunkFileNames: 'chunks/lib-[hash].js',
|
||||||
format: 'cjs'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dir: 'dist',
|
|
||||||
entryFileNames: '[name].mjs',
|
|
||||||
chunkFileNames: 'chunks/lib-[hash].mjs',
|
|
||||||
format: 'es'
|
format: 'es'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -7,7 +7,7 @@ const msgPath = process.argv[2]
|
|||||||
const msg = fs.readFileSync(msgPath, 'utf-8').trim()
|
const msg = fs.readFileSync(msgPath, 'utf-8').trim()
|
||||||
|
|
||||||
const commitRE =
|
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)) {
|
if (!commitRE.test(msg)) {
|
||||||
console.log()
|
console.log()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { build as viteBuild } from 'vite'
|
import { build as viteBuild } from 'vite'
|
||||||
import { InlineConfig, resolveConfig } from './config'
|
import { type InlineConfig, resolveConfig } from './config'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bundles the electron app for production.
|
* Bundles the electron app for production.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { cac } from 'cac'
|
import { cac } from 'cac'
|
||||||
import colors from 'picocolors'
|
import colors from 'picocolors'
|
||||||
import { LogLevel, createLogger } from 'vite'
|
import { type LogLevel, createLogger } from 'vite'
|
||||||
import { InlineConfig } from './config'
|
import type { InlineConfig } from './config'
|
||||||
import { version } from '../package.json'
|
import { version } from '../package.json'
|
||||||
|
|
||||||
const cli = cac('electron-vite')
|
const cli = cac('electron-vite')
|
||||||
|
@ -343,7 +343,7 @@ async function bundleConfigFile(fileName: string, isESM: boolean): Promise<{ cod
|
|||||||
absWorkingDir: process.cwd(),
|
absWorkingDir: process.cwd(),
|
||||||
entryPoints: [fileName],
|
entryPoints: [fileName],
|
||||||
write: false,
|
write: false,
|
||||||
target: ['node18'],
|
target: ['node20'],
|
||||||
platform: 'node',
|
platform: 'node',
|
||||||
bundle: true,
|
bundle: true,
|
||||||
format: isESM ? 'esm' : 'cjs',
|
format: isESM ? 'esm' : 'cjs',
|
||||||
@ -417,6 +417,7 @@ async function loadConfigFormBundledFile(
|
|||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(fileNameTmp)
|
fs.unlinkSync(fileNameTmp)
|
||||||
|
// eslint-disable-next-line no-empty
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -69,6 +69,12 @@ export function getElectronNodeTarget(): string {
|
|||||||
const electronVer = getElectronMajorVer()
|
const electronVer = getElectronMajorVer()
|
||||||
|
|
||||||
const nodeVer = {
|
const nodeVer = {
|
||||||
|
'37': '22.16',
|
||||||
|
'36': '22.14',
|
||||||
|
'35': '22.14',
|
||||||
|
'34': '20.18',
|
||||||
|
'33': '20.18',
|
||||||
|
'32': '20.16',
|
||||||
'31': '20.14',
|
'31': '20.14',
|
||||||
'30': '20.11',
|
'30': '20.11',
|
||||||
'29': '20.9',
|
'29': '20.9',
|
||||||
@ -82,12 +88,7 @@ export function getElectronNodeTarget(): string {
|
|||||||
'21': '16.16',
|
'21': '16.16',
|
||||||
'20': '16.15',
|
'20': '16.15',
|
||||||
'19': '16.14',
|
'19': '16.14',
|
||||||
'18': '16.13',
|
'18': '16.13'
|
||||||
'17': '16.13',
|
|
||||||
'16': '16.9',
|
|
||||||
'15': '16.5',
|
|
||||||
'14': '14.17',
|
|
||||||
'13': '14.17'
|
|
||||||
}
|
}
|
||||||
if (electronVer && parseInt(electronVer) > 10) {
|
if (electronVer && parseInt(electronVer) > 10) {
|
||||||
let target = nodeVer[electronVer]
|
let target = nodeVer[electronVer]
|
||||||
@ -101,6 +102,12 @@ export function getElectronChromeTarget(): string {
|
|||||||
const electronVer = getElectronMajorVer()
|
const electronVer = getElectronMajorVer()
|
||||||
|
|
||||||
const chromeVer = {
|
const chromeVer = {
|
||||||
|
'37': '138',
|
||||||
|
'36': '136',
|
||||||
|
'35': '134',
|
||||||
|
'34': '132',
|
||||||
|
'33': '130',
|
||||||
|
'32': '128',
|
||||||
'31': '126',
|
'31': '126',
|
||||||
'30': '124',
|
'30': '124',
|
||||||
'29': '122',
|
'29': '122',
|
||||||
@ -114,12 +121,7 @@ export function getElectronChromeTarget(): string {
|
|||||||
'21': '106',
|
'21': '106',
|
||||||
'20': '104',
|
'20': '104',
|
||||||
'19': '102',
|
'19': '102',
|
||||||
'18': '100',
|
'18': '100'
|
||||||
'17': '98',
|
|
||||||
'16': '96',
|
|
||||||
'15': '94',
|
|
||||||
'14': '93',
|
|
||||||
'13': '91'
|
|
||||||
}
|
}
|
||||||
if (electronVer && parseInt(electronVer) > 10) {
|
if (electronVer && parseInt(electronVer) > 10) {
|
||||||
let target = chromeVer[electronVer]
|
let target = chromeVer[electronVer]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export { type LogLevel, createLogger, mergeConfig, splitVendorChunkPlugin, splitVendorChunk } from 'vite'
|
export { type LogLevel, createLogger, mergeConfig } from 'vite'
|
||||||
export * from './config'
|
export * from './config'
|
||||||
export { createServer } from './server'
|
export { createServer } from './server'
|
||||||
export { build } from './build'
|
export { build } from './build'
|
||||||
|
@ -115,7 +115,7 @@ export default function assetPlugin(): Plugin {
|
|||||||
const hash = this.emitFile({
|
const hash = this.emitFile({
|
||||||
type: 'asset',
|
type: 'asset',
|
||||||
name: path.basename(file),
|
name: path.basename(file),
|
||||||
source
|
source: source as unknown as Uint8Array
|
||||||
})
|
})
|
||||||
referenceId = `__VITE_NODE_ASSET__${hash}__`
|
referenceId = `__VITE_NODE_ASSET__${hash}__`
|
||||||
assetCache.set(file, referenceId)
|
assetCache.set(file, referenceId)
|
||||||
|
@ -310,7 +310,7 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
const chunkFileName = path.resolve(outDir, name)
|
const chunkFileName = path.resolve(outDir, name)
|
||||||
if (bytecodeChunks.includes(name)) {
|
if (bytecodeChunks.includes(name)) {
|
||||||
const bytecodeBuffer = await compileToBytecode(_code)
|
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 (chunk.isEntry) {
|
||||||
if (!removeBundleJS) {
|
if (!removeBundleJS) {
|
||||||
keepBundle(chunkFileName)
|
keepBundle(chunkFileName)
|
||||||
@ -344,7 +344,9 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName)
|
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)
|
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 format = pkg.type && pkg.type === 'module' && supportESM() ? 'es' : 'cjs'
|
||||||
|
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
|
ssr: {
|
||||||
|
resolve: {
|
||||||
|
conditions: ['module', 'browser', 'development|production'],
|
||||||
|
mainFields: ['browser', 'module', 'jsnext:main', 'jsnext']
|
||||||
|
}
|
||||||
|
},
|
||||||
build: {
|
build: {
|
||||||
outDir: path.resolve(root, 'out', 'preload'),
|
outDir: path.resolve(root, 'out', 'preload'),
|
||||||
target: nodeTarget,
|
target: nodeTarget,
|
||||||
@ -272,7 +278,8 @@ export function electronPreloadVitePlugin(options?: ElectronPluginOptions): Plug
|
|||||||
// enable ssr build
|
// enable ssr build
|
||||||
config.build.ssr = true
|
config.build.ssr = true
|
||||||
config.build.ssrEmitAssets = 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 {
|
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 {
|
export function toRelativePath(filename: string, importer: string): string {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2022",
|
"target": "ES2023",
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"lib": ["ESNext"],
|
"lib": ["ESNext"],
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "bundler",
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user