From 2ba359f4ed8069ac10c08cc58d0d5705e7df9b5f Mon Sep 17 00:00:00 2001 From: endiliey Date: Wed, 1 Aug 2018 18:09:35 +0800 Subject: [PATCH] chore: delay starting webpack-serve by one second --- lib/commands/dev.js | 60 +++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/lib/commands/dev.js b/lib/commands/dev.js index 46559011e5..494a0303b2 100644 --- a/lib/commands/dev.js +++ b/lib/commands/dev.js @@ -78,35 +78,37 @@ module.exports = async function dev(sourceDir, cliOptions = {}) { // webpack-serve const nonExistentDir = path.resolve(__dirname, 'non-existent'); - await serve( - {}, - { - content: [nonExistentDir], - compiler, - open: false, - devMiddleware: { - logLevel: 'silent' - }, - hotClient: { - port: port + 1, - logLevel: 'error' - }, - logLevel: 'error', - port, - add: (app, middleware, options) => { - const staticDir = path.resolve(sourceDir, 'public'); - if (fs.existsSync(staticDir)) { - app.use(mount(publicPath, serveStatic(staticDir))); + setTimeout(async () => { + await serve( + {}, + { + content: [nonExistentDir], + compiler, + open: false, + devMiddleware: { + logLevel: 'silent' + }, + hotClient: { + port: port + 1, + logLevel: 'error' + }, + logLevel: 'error', + port, + add: (app, middleware, options) => { + const staticDir = path.resolve(sourceDir, 'public'); + if (fs.existsSync(staticDir)) { + app.use(mount(publicPath, serveStatic(staticDir))); + } + app.use(range); // enable range request https://tools.ietf.org/html/rfc7233 + app.use( + convert( + history({ + rewrites: [{from: /\.html$/, to: '/'}] + }) + ) + ); } - app.use(range); // enable range request https://tools.ietf.org/html/rfc7233 - app.use( - convert( - history({ - rewrites: [{from: /\.html$/, to: '/'}] - }) - ) - ); } - } - ); + ); + }, 1000); };