Skip to content

Commit

Permalink
fix: worker reload get new port will lead static file error
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl committed Oct 11, 2018
1 parent 568c948 commit b532423
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 3 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class WebpackServer extends WebpackTool {
constructor(agent, config) {
super(config);
this.agent = agent;
this.port = Utils.getPort(config.port);
}

start() {
Expand All @@ -19,15 +20,15 @@ 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();
}

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 => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit b532423

Please sign in to comment.