diff --git a/app.js b/app.js index 1ea895e..51c21b1 100644 --- a/app.js +++ b/app.js @@ -4,7 +4,6 @@ const fs = require('fs'); const WebpackTool = require('webpack-tool'); const convert = require('koa-convert'); const proxy = require('./lib/proxy'); -const utils = require('./lib/utils'); const Constant = require('./lib/constant'); module.exports = app => { app.use(function* (next) { @@ -24,7 +23,7 @@ module.exports = app => { app.messenger.on(Constant.EVENT_WEBPACK_BUILD_STATE, data => { app.WEBPACK_BUILD_READY = data.state; const config = app.config.webpack; - const port = utils.getPort(data.port || config.port); + const port = data.port; if (config.proxy) { if (typeof config.proxy === 'boolean') { config.proxy = { diff --git a/config/config.default.js b/config/config.default.js index 2734258..89089ca 100644 --- a/config/config.default.js +++ b/config/config.default.js @@ -7,7 +7,7 @@ module.exports = () => { * webpack build config * @property {Number} port - webpack dev server port * @property {Object} proxy - static resource http relative path mapping to true path @see https://github.com/popomore/koa-proxy - * /public/client/js/vendor.js -> http://ip:port//public/client/js/vendor.js + * /public/client/js/vendor.js -> http://ip:port//public/client/js/vendor.js * @property {Object} proxyMapping support proxy mapping, default js/css/json, not support image * @property {Array} [webpackConfigList] - webpack building config */ diff --git a/lib/server.js b/lib/server.js index 72f9753..f55b510 100644 --- a/lib/server.js +++ b/lib/server.js @@ -7,6 +7,7 @@ class WebpackServer extends WebpackTool { constructor(agent, config) { super(config); this.agent = agent; + this.port = Utils.getPort(config.port); } start() { @@ -19,7 +20,7 @@ class WebpackServer extends WebpackTool { } finish() { - this.agent.messenger.sendToApp(Constant.EVENT_WEBPACK_BUILD_STATE, { state: true }); + this.agent.messenger.sendToApp(Constant.EVENT_WEBPACK_BUILD_STATE, { state: true, port: this.port }); this.endTime = Date.now(); console.log(`webpack build cost:${this.endTime - this.startTime}ms`); this.openBrowser(); @@ -27,7 +28,7 @@ class WebpackServer extends WebpackTool { listen(compilers) { this.agent.messenger.on(Constant.EVENT_WEBPACK_BUILD_STATE, () => { - this.agent.messenger.sendToApp(Constant.EVENT_WEBPACK_BUILD_STATE, { state: this.ready }); + this.agent.messenger.sendToApp(Constant.EVENT_WEBPACK_BUILD_STATE, { state: this.ready, port: this.port }); }); this.agent.messenger.on(Constant.EVENT_WEBPACK_READ_FILE_MEMORY, data => { diff --git a/package.json b/package.json index 1d881d5..c0541e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "egg-webpack", - "version": "4.4.1", + "version": "4.4.2", "description": "webpack dev server plugin for egg, support read file in memory and hot reload.", "eggPlugin": { "name": "webpack",