Compare commits

...

3 Commits

Author SHA1 Message Date
alex8088
4f12196e54 feat: support vite 5 2023-12-08 22:09:49 +08:00
alex8088
b93a1878c1 feat: migrate to ESM 2023-12-08 22:03:47 +08:00
alex8088
8bb03f8b24 feat: bump minimum node version to 18 2023-12-08 21:35:06 +08:00
9 changed files with 43 additions and 20 deletions

View File

@ -8,7 +8,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2021
ecmaVersion: 2022
},
plugins: ['@typescript-eslint'],
extends: [

View File

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

View File

@ -2,8 +2,20 @@
"name": "electron-vite",
"version": "1.0.29",
"description": "Electron build tooling based on Vite",
"main": "dist/index.js",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./node": {
"types": "./node.d.ts"
}
},
"bin": {
"electron-vite": "bin/electron-vite.js"
},
@ -13,7 +25,7 @@
"node.d.ts"
],
"engines": {
"node": "^14.18.0 || >=16.0.0"
"node": "^18.0.0 || >=20.0.0"
},
"packageManager": "pnpm@8.6.10",
"author": "Alex Wei<https://github.com/alex8088>",
@ -53,7 +65,7 @@
},
"peerDependencies": {
"@swc/core": "^1.0.0",
"vite": "^3.0.0 || ^4.0.0"
"vite": "^4.0.0 || ^5.0.0"
},
"peerDependenciesMeta": {
"@swc/core": {

View File

@ -30,12 +30,20 @@ function clean(when: 'buildStart' | 'buildEnd', target: string): Plugin {
export default defineConfig([
{
input: ['src/index.ts', 'src/cli.ts'],
output: {
dir: 'dist',
entryFileNames: '[name].js',
chunkFileNames: 'chunks/lib-[hash].js',
format: 'cjs'
},
output: [
{
dir: 'dist',
entryFileNames: '[name].cjs',
chunkFileNames: 'chunks/lib-[hash].cjs',
format: 'cjs'
},
{
dir: 'dist',
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/lib-[hash].mjs',
format: 'es'
}
],
external,
plugins: [
clean('buildStart', 'dist'),

View File

@ -1,7 +1,7 @@
// Invoked on the commit-msg git hook by simple-git-hooks.
const colors = require('picocolors')
const fs = require('fs')
import colors from 'picocolors'
import fs from 'node:fs'
const msgPath = process.argv[2]
const msg = fs.readFileSync(msgPath, 'utf-8').trim()

View File

@ -1,8 +1,11 @@
import { createRequire } from 'node:module'
import { cac } from 'cac'
import colors from 'picocolors'
import { LogLevel, createLogger } from 'vite'
import { InlineConfig } from './config'
const _require = createRequire(import.meta.url)
const cli = cac('electron-vite')
// global options
@ -160,6 +163,6 @@ cli
})
cli.help()
cli.version(require('../package.json').version)
cli.version(_require('../package.json').version)
cli.parse()

View File

@ -316,7 +316,7 @@ async function bundleConfigFile(fileName: string, isESM: boolean): Promise<{ cod
absWorkingDir: process.cwd(),
entryPoints: [fileName],
write: false,
target: ['node14.18', 'node16'],
target: ['node18'],
platform: 'node',
bundle: true,
format: isESM ? 'esm' : 'cjs',

View File

@ -9,7 +9,7 @@ const ensureElectronEntryFile = (root = process.cwd()): void => {
if (process.env.ELECTRON_ENTRY) return
const pkg = path.join(root, 'package.json')
if (fs.existsSync(pkg)) {
const main = require(pkg).main
const main = _require(pkg).main
if (!main) {
throw new Error('No entry point found for electron app, please add a "main" field to package.json')
} else {

View File

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