mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +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 * as vite from 'vite'
|
||||||
import vuePlugin from '@vitejs/plugin-vue'
|
import vuePlugin from '@vitejs/plugin-vue'
|
||||||
import { mkdirp, writeFile } from 'fs-extra'
|
import { mkdirp, writeFile } from 'fs-extra'
|
||||||
import debounce from 'debounce'
|
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import { ViteBuildContext, ViteOptions } from './vite'
|
import { ViteBuildContext, ViteOptions } from './vite'
|
||||||
import { wpfs } from './utils/wpfs'
|
import { wpfs } from './utils/wpfs'
|
||||||
@ -62,15 +61,31 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const build = debounce(async () => {
|
let lastBuild = 0
|
||||||
const start = Date.now()
|
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 vite.build(serverConfig)
|
||||||
await onBuild()
|
await onBuild()
|
||||||
consola.info(`Server built in ${Date.now() - start}ms`)
|
consola.info(`Server built in ${Date.now() - start}ms`)
|
||||||
}, 300)
|
}
|
||||||
|
|
||||||
await build()
|
await build()
|
||||||
|
|
||||||
ctx.nuxt.hook('builder:watch', () => build())
|
ctx.nuxt.hook('builder:watch', () => build())
|
||||||
ctx.nuxt.hook('app:templatesGenerated', () => 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