From 516cefa15239fd06ff87a1aacc7c61d45197b107 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Fri, 27 Aug 2021 14:30:32 +0800 Subject: [PATCH] fix: compatible with webpack-dev-server v3 --- packages/build-scripts/CHANGELOG.md | 4 ++ .../build-scripts/bin/child-process-start.js | 8 +++- packages/build-scripts/package.json | 2 +- packages/build-scripts/src/service/start.ts | 37 +++++++++++++++---- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/packages/build-scripts/CHANGELOG.md b/packages/build-scripts/CHANGELOG.md index e6f88a2..6adf1ec 100644 --- a/packages/build-scripts/CHANGELOG.md +++ b/packages/build-scripts/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.1 + +- [fix] compatible with webpack-dev-server v3 + ## 1.1.0 - [refactor] support custom command by extend Context diff --git a/packages/build-scripts/bin/child-process-start.js b/packages/build-scripts/bin/child-process-start.js index 5e36bd5..11f12d4 100644 --- a/packages/build-scripts/bin/child-process-start.js +++ b/packages/build-scripts/bin/child-process-start.js @@ -48,8 +48,12 @@ const defaultPort = parseInt(DEFAULT_PORT || 3333, 10); }); ['SIGINT', 'SIGTERM'].forEach(function(sig) { - process.on(sig, function() { - devServer.close(); + process.on(sig, async function() { + if (devServer.close) { + devServer.close(); + } else if (devServer.stop) { + await devServer.stop(); + } process.exit(0); }); }); diff --git a/packages/build-scripts/package.json b/packages/build-scripts/package.json index 427a7c9..5c7659f 100644 --- a/packages/build-scripts/package.json +++ b/packages/build-scripts/package.json @@ -1,6 +1,6 @@ { "name": "build-scripts", - "version": "1.1.0", + "version": "1.1.1", "license": "MIT", "description": "scripts core", "main": "lib/index.js", diff --git a/packages/build-scripts/src/service/start.ts b/packages/build-scripts/src/service/start.ts index c35b2de..31df75a 100644 --- a/packages/build-scripts/src/service/start.ts +++ b/packages/build-scripts/src/service/start.ts @@ -86,27 +86,50 @@ export = async function(context: Context, options?: IRunOptions): Promise { - applyHook(`after.${command}.devServer`, { + if (devServer.startCallback) { + devServer.startCallback( + () => { + applyHook(`after.${command}.devServer`, { + url: serverUrl, + urls, + devServer, + }); + }, + ); + } else { + devServer.listen(devServerConfig.port, devServerConfig.host, async (err: Error) => { + if (err) { + log.info('WEBPACK',chalk.red('[ERR]: Failed to start webpack dev server')); + log.error('WEBPACK', (err.stack || err.toString())); + } + await applyHook(`after.${command}.devServer`, { url: serverUrl, urls, devServer, + err, }); - }, - ); + }); + } + return devServer; };