feat: migrate to ESM
This commit is contained in:
parent
8bb03f8b24
commit
b93a1878c1
|
@ -24,7 +24,7 @@ if (debugIndex > 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
require('../dist/cli')
|
import('../dist/cli.mjs')
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
14
package.json
14
package.json
|
@ -2,8 +2,20 @@
|
||||||
"name": "electron-vite",
|
"name": "electron-vite",
|
||||||
"version": "1.0.29",
|
"version": "1.0.29",
|
||||||
"description": "Electron build tooling based on Vite",
|
"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",
|
"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": {
|
"bin": {
|
||||||
"electron-vite": "bin/electron-vite.js"
|
"electron-vite": "bin/electron-vite.js"
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,12 +30,20 @@ function clean(when: 'buildStart' | 'buildEnd', target: string): Plugin {
|
||||||
export default defineConfig([
|
export default defineConfig([
|
||||||
{
|
{
|
||||||
input: ['src/index.ts', 'src/cli.ts'],
|
input: ['src/index.ts', 'src/cli.ts'],
|
||||||
output: {
|
output: [
|
||||||
|
{
|
||||||
dir: 'dist',
|
dir: 'dist',
|
||||||
entryFileNames: '[name].js',
|
entryFileNames: '[name].cjs',
|
||||||
chunkFileNames: 'chunks/lib-[hash].js',
|
chunkFileNames: 'chunks/lib-[hash].cjs',
|
||||||
format: 'cjs'
|
format: 'cjs'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
dir: 'dist',
|
||||||
|
entryFileNames: '[name].mjs',
|
||||||
|
chunkFileNames: 'chunks/lib-[hash].mjs',
|
||||||
|
format: 'es'
|
||||||
|
}
|
||||||
|
],
|
||||||
external,
|
external,
|
||||||
plugins: [
|
plugins: [
|
||||||
clean('buildStart', 'dist'),
|
clean('buildStart', 'dist'),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Invoked on the commit-msg git hook by simple-git-hooks.
|
// Invoked on the commit-msg git hook by simple-git-hooks.
|
||||||
|
|
||||||
const colors = require('picocolors')
|
import colors from 'picocolors'
|
||||||
const fs = require('fs')
|
import fs from 'node:fs'
|
||||||
|
|
||||||
const msgPath = process.argv[2]
|
const msgPath = process.argv[2]
|
||||||
const msg = fs.readFileSync(msgPath, 'utf-8').trim()
|
const msg = fs.readFileSync(msgPath, 'utf-8').trim()
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
import { createRequire } from 'node:module'
|
||||||
import { cac } from 'cac'
|
import { cac } from 'cac'
|
||||||
import colors from 'picocolors'
|
import colors from 'picocolors'
|
||||||
import { LogLevel, createLogger } from 'vite'
|
import { LogLevel, createLogger } from 'vite'
|
||||||
import { InlineConfig } from './config'
|
import { InlineConfig } from './config'
|
||||||
|
|
||||||
|
const _require = createRequire(import.meta.url)
|
||||||
|
|
||||||
const cli = cac('electron-vite')
|
const cli = cac('electron-vite')
|
||||||
|
|
||||||
// global options
|
// global options
|
||||||
|
@ -160,6 +163,6 @@ cli
|
||||||
})
|
})
|
||||||
|
|
||||||
cli.help()
|
cli.help()
|
||||||
cli.version(require('../package.json').version)
|
cli.version(_require('../package.json').version)
|
||||||
|
|
||||||
cli.parse()
|
cli.parse()
|
||||||
|
|
|
@ -9,7 +9,7 @@ const ensureElectronEntryFile = (root = process.cwd()): void => {
|
||||||
if (process.env.ELECTRON_ENTRY) return
|
if (process.env.ELECTRON_ENTRY) return
|
||||||
const pkg = path.join(root, 'package.json')
|
const pkg = path.join(root, 'package.json')
|
||||||
if (fs.existsSync(pkg)) {
|
if (fs.existsSync(pkg)) {
|
||||||
const main = require(pkg).main
|
const main = _require(pkg).main
|
||||||
if (!main) {
|
if (!main) {
|
||||||
throw new Error('No entry point found for electron app, please add a "main" field to package.json')
|
throw new Error('No entry point found for electron app, please add a "main" field to package.json')
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue