您现在的位置是:首页 >技术交流 >跟着满哥学vue(vite配置electron篇)网站首页技术交流
跟着满哥学vue(vite配置electron篇)
简介跟着满哥学vue(vite配置electron篇)
直接空降小满zs(Vue3 Vite electron 开发桌面程序)
谈谈我遇到的坑(2025-2-9)
1.由于vite是基于esm,所以直接使用commonJS的require会报错

使用import代替require即可解决问题
const initElectron = async () => {
//使用esbuild编译Typescript代码为Javascript
//@ts-ignore
const esbuild = await import('esbuild')
esbuild.buildSync({
entryPoints: ['src/background.ts'],
bundle: true,
outfile: 'dist/background.js',
platform: 'node',
target: 'node12',
external: ['electron']
})
}
这个报错也是因为vite不会打包commonJS的文件,所以需要指定打包版本为esm,在buildSync添加format:'esm’即可

const initElectron = async () => {
//使用esbuild编译Typescript代码为Javascript
//@ts-ignore
const esbuild = await import('esbuild')
esbuild.buildSync({
entryPoints: ['src/background.ts'],
bundle: true,
outfile: 'dist/background.js',
platform: 'node',
format:"esm",
target: 'node12',
external: ['electron']
})
}
风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。





U8W/U8W-Mini使用与常见问题解决
QT多线程的5种用法,通过使用线程解决UI主界面的耗时操作代码,防止界面卡死。...
stm32使用HAL库配置串口中断收发数据(保姆级教程)
分享几个国内免费的ChatGPT镜像网址(亲测有效)
Allegro16.6差分等长设置及走线总结