chore: 升级 vite@2.0
This commit is contained in:
@@ -7,9 +7,9 @@ import { watch, rollup, OutputOptions } from 'rollup'
|
||||
import minimist from 'minimist'
|
||||
import chalk from 'chalk'
|
||||
import ora from 'ora'
|
||||
import waitOn from 'wait-on'
|
||||
import electron from 'electron'
|
||||
import dotenv from 'dotenv'
|
||||
import { waitOn } from './utils'
|
||||
import options from './rollup.config'
|
||||
import { main } from '../package.json'
|
||||
|
||||
@@ -21,16 +21,7 @@ const TAG = '[script/build.ts]'
|
||||
const spinner = ora(`${TAG} Electron build...`)
|
||||
|
||||
if (argv.watch) {
|
||||
waitOn({
|
||||
resources: [`http://localhost:${process.env.PORT}`],
|
||||
log: false,
|
||||
}, err => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// once here, all resources are available
|
||||
waitOn({ port: process.env.PORT as string }).then(msg => {
|
||||
const watcher = watch(opt)
|
||||
let child: ChildProcess
|
||||
watcher.on('change', filename => {
|
||||
|
||||
18
script/utils.ts
Normal file
18
script/utils.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { get } from 'http'
|
||||
|
||||
/** 轮询监听 vite 启动 */
|
||||
export function waitOn(arg0: { port: string | number; interval?: number; }) {
|
||||
return new Promise(resolve => {
|
||||
const { port, interval = 149 } = arg0
|
||||
let counter = 0
|
||||
const timer: NodeJS.Timer = setInterval(() => {
|
||||
get(`http://localhost:${port}`, res => {
|
||||
clearInterval(timer)
|
||||
console.log('[waitOn]', res.statusCode, res.statusMessage)
|
||||
resolve(res.statusCode)
|
||||
}).on('error', err => {
|
||||
console.log('[waitOn]', `counter:${counter++}`)
|
||||
})
|
||||
}, interval)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user