Skip to content

Commit

Permalink
fix: egg static resource no proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl committed Mar 8, 2018
1 parent 92f2069 commit 460b57c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 4 additions & 2 deletions agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ module.exports = agent => {
if (config.webpackConfigList && !Array.isArray(config.webpackConfigList)) {
config.webpackConfigList = [config.webpackConfigList];
}
// webpack-tool not need proxy again
const serverConfig = Object.assign({}, config, { proxy: false });
if (Utils.isUseMultProcess(agent.baseDir, config)) {
new MultProcessWebpackServer(agent, config).start();
new MultProcessWebpackServer(agent, serverConfig).start();
} else {
new WebpackServer(agent, config).start();
new WebpackServer(agent, serverConfig).start();
}
});
};
14 changes: 12 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';
const path = require('path');
const fs = require('fs');
const proxy = require('koa-proxy');
const Constant = require('./lib/constant');
module.exports = app => {
const config = app.config.webpack;
app.use(function* (next) {
if (app.webpack_build_success) {
yield* next;
Expand All @@ -16,7 +16,17 @@ module.exports = app => {
}
}
});

const config = app.config.webpack;
if (config.proxy) {
if (typeof config.proxy === 'boolean') {
config.proxy = {
host: 'http://127.0.0.1:9000',
match: /^\/public\//,
yieldNext: true,
};
}
app.use(proxy(config.proxy));
}
app.messenger.setMaxListeners(config.maxListeners || 10000);

app.messenger.on(Constant.EVENT_WEBPACK_BUILD_STATE, data => {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "egg-webpack",
"version": "4.0.2",
"version": "4.0.3",
"description": "webpack dev server plugin for egg, support read file in memory and hot reload.",
"eggPlugin": {
"name": "webpack",
Expand All @@ -17,6 +17,7 @@
"hot-reload"
],
"dependencies": {
"koa-proxy": "^0.9.0",
"mkdirp": "^0.5.1",
"webpack-tool": "^4.0.0"
},
Expand Down

0 comments on commit 460b57c

Please sign in to comment.