首先,我想说,我已经开始使用 Vite 有一段时间了,而且我不是任何形式的 Vite 专家。
现在,关于我的问题:我正在开发一个 Chrome 扩展,它要求我在/dist
文件夹。使用起来效果很好vite build
。但是,如果我尝试只使用vite
(为了获得 HMR 的好处),在/dist
文件夹。所以我无法加载Chrome扩展程序。
如果有人遇到过类似的问题,或者知道我忽略的配置,请随时在这里分享。
Thanks!
有了这个小插件,你将得到一个build
在每个热模块重新加载事件之后:
在一个文件中hot-build.ts
:
/**
* Custom Hot Reloading Plugin
* Start `vite build` on Hot Module Reload
*/
import { build } from 'vite'
export default function HotBuild() {
let bundling = false
const hmrBuild = async () => {
bundling = true
await build({'build': { outDir: './hot-dist'}}) // <--- you can give a custom config here or remove it to use default options
};
return {
name: 'hot-build',
enforce: "pre",
// HMR
handleHotUpdate({ file, server }) {
if (!bundling) {
console.log(`hot vite build starting...`)
hmrBuild()
.then(() => {
bundling = false
console.log(`hot vite build finished`)
})
}
return []
}
}
}
then in vite.config.js
:
import HotBuild from './hot-build'
// vite config
{
plugins: [
HotBuild()
],
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)