Skip to content

Commit

Permalink
fix[mock]: fixed mock-server hot reload bug in windows (PanJiaChen#1939)
Browse files Browse the repository at this point in the history
  • Loading branch information
dingangang authored and Trong. Pham Van - CMC Global DU1.19 committed Jul 22, 2022
1 parent 942a353 commit efb6748
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions mock/mock-server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
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
Expand All @@ -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)]
}
})
Expand All @@ -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') {
Expand Down

0 comments on commit efb6748

Please sign in to comment.