2022-03-26 17:08:36 +00:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
|
|
|
export default defineConfig({
|
2022-06-20 12:57:51 +00:00
|
|
|
experimental: {
|
|
|
|
hmrPartialAccept: true
|
|
|
|
},
|
2020-12-29 21:29:51 +00:00
|
|
|
plugins: [
|
|
|
|
{
|
|
|
|
name: 'mock-custom',
|
2021-01-02 17:58:54 +00:00
|
|
|
async handleHotUpdate({ file, read, server }) {
|
2020-12-29 21:29:51 +00:00
|
|
|
if (file.endsWith('customFile.js')) {
|
|
|
|
const content = await read()
|
|
|
|
const msg = content.match(/export const msg = '(\w+)'/)[1]
|
2022-03-26 17:08:36 +00:00
|
|
|
server.ws.send('custom:foo', { msg })
|
2020-12-29 21:29:51 +00:00
|
|
|
}
|
2022-03-26 14:42:07 +00:00
|
|
|
},
|
|
|
|
configureServer(server) {
|
2022-03-26 17:08:36 +00:00
|
|
|
server.ws.on('custom:remote-add', ({ a, b }, client) => {
|
|
|
|
client.send('custom:remote-add-result', { result: a + b })
|
2022-03-26 14:42:07 +00:00
|
|
|
})
|
2020-12-29 21:29:51 +00:00
|
|
|
}
|
2022-09-19 12:34:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'virtual-file',
|
|
|
|
resolveId(id) {
|
|
|
|
if (id === 'virtual:file') {
|
|
|
|
return '\0virtual:file'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
load(id) {
|
|
|
|
if (id === '\0virtual:file') {
|
|
|
|
return 'import { virtual } from "/importedVirtual.js"; export { virtual };'
|
|
|
|
}
|
|
|
|
}
|
2020-12-29 21:29:51 +00:00
|
|
|
}
|
|
|
|
]
|
2022-03-26 17:08:36 +00:00
|
|
|
})
|