mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix: vite build (#311)
This commit is contained in:
parent
ea0fdc2aa2
commit
9e8b042bad
@ -2,7 +2,6 @@ import { resolve } from 'upath'
|
||||
import * as vite from 'vite'
|
||||
import vuePlugin from '@vitejs/plugin-vue'
|
||||
import { mkdirp, writeFile } from 'fs-extra'
|
||||
import debounce from 'debounce'
|
||||
import consola from 'consola'
|
||||
import { ViteBuildContext, ViteOptions } from './vite'
|
||||
import { wpfs } from './utils/wpfs'
|
||||
@ -62,15 +61,31 @@ export async function buildServer (ctx: ViteBuildContext) {
|
||||
return
|
||||
}
|
||||
|
||||
const build = debounce(async () => {
|
||||
const start = Date.now()
|
||||
let lastBuild = 0
|
||||
const build = async () => {
|
||||
let start = Date.now()
|
||||
// debounce
|
||||
if (start - lastBuild < 300) {
|
||||
await sleep(300 - (start - lastBuild) + 1)
|
||||
start = Date.now()
|
||||
if (start - lastBuild < 300) {
|
||||
return
|
||||
}
|
||||
}
|
||||
lastBuild = start
|
||||
await vite.build(serverConfig)
|
||||
await onBuild()
|
||||
consola.info(`Server built in ${Date.now() - start}ms`)
|
||||
}, 300)
|
||||
}
|
||||
|
||||
await build()
|
||||
|
||||
ctx.nuxt.hook('builder:watch', () => build())
|
||||
ctx.nuxt.hook('app:templatesGenerated', () => build())
|
||||
}
|
||||
|
||||
function sleep (ms:number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user