THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

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

tags/4.1.0
dingangang 花裤衩 11 months ago
parent
commit
ea91066b18
1 changed files with 6 additions and 4 deletions
  1. +6
    -4
      mock/mock-server.js

+ 6
- 4
mock/mock-server.js View File

@@ -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
@@ -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') {


Loading…
Cancel
Save