-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
declare global { | ||
/** | ||
* dev Server 第一次启动标识 | ||
*/ | ||
var $devServerFirstStarted: boolean | ||
} | ||
|
||
setImmediate(() => { | ||
global.$devServerFirstStarted = true | ||
}) | ||
|
||
/** | ||
* 仅第一次启动服务时允许 | ||
*/ | ||
export const runOnDevServerFirstStart = ( | ||
callback: Function | ||
) => { | ||
if (!global.$devServerFirstStarted) { | ||
callback() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { watch } from 'chokidar' | ||
import { runOnDevServerFirstStart } from './global' | ||
import { utimesSync, openSync, closeSync } from 'fs' | ||
|
||
runOnDevServerFirstStart(() => { | ||
const restart = () => { | ||
const time = new Date() | ||
const path = 'vite.config.ts' | ||
try { | ||
utimesSync(path, time, time) | ||
} catch (error) { | ||
closeSync(openSync(path, 'w')) | ||
} | ||
} | ||
|
||
const layoutsWatcher = watch('./src/layouts', { | ||
ignoreInitial: true | ||
}) | ||
|
||
layoutsWatcher.on('add', restart) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters