提交 ea91066b 编写于 作者: D dingangang 提交者: 花裤衩

fix[mock]: fixed mock-server hot reload bug in windows (#1939)

上级 50d09574
const chokidar = require('chokidar')
const bodyParser = require('body-parser')
const chalk = require('chalk')
const path = require('path')
const mockDir = path.join(process.cwd(), 'mock')
function registerRoutes(app) {
let mockLastIndex
......@@ -18,7 +21,7 @@ function registerRoutes(app) {
function unregisterRoutes() {
Object.keys(require.cache).forEach(i => {
if (i.includes('/mock')) {
if (i.includes(mockDir)) {
delete require.cache[require.resolve(i)]
}
})
......@@ -40,9 +43,8 @@ module.exports = app => {
var mockStartIndex = mockRoutes.mockStartIndex
// watch files, hot reload mock server
chokidar.watch(('./mock'), {
ignored: 'mock/mock-server.js',
persistent: true,
chokidar.watch(mockDir, {
ignored: /mock-server/,
ignoreInitial: true
}).on('all', (event, path) => {
if (event === 'change' || event === 'add') {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册