Skip to content

Commit ff2056e

Browse files
committed
fix: compatible old version for dll and add use doc
1 parent ba670ba commit ff2056e

5 files changed

Lines changed: 76 additions & 13 deletions

File tree

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
webpack dev server plugin for egg, support read file in memory and hot reload. [More Detail](http://hubcarl.github.io/blog/2017/04/15/egg-webpack/)
2424

25+
- support webpack native configuration by `webpack.webpackConfigList`
26+
- when no config `webpack.webpackConfigList`, egg-webpack will dynamic create webpack config by `webpack.config.js(easywebpack)`, and start multiple process build.
2527

2628
## Install
2729

@@ -41,15 +43,68 @@ exports.webpack = {
4143

4244
## Configuration
4345

46+
support native webpack config and easywebpack webpack config
47+
4448
```js
4549
// {app_root}/config/config.default.js
4650
exports.webpack = {
47-
// port: 8090,
51+
// port: 9000,
4852
// proxy: true,
4953
// webpackConfigList: [],
5054
};
5155
```
5256

57+
**port**: {Number}, default 9000. webpack dev server port, default 9000, when hava multile webpack config, the port incremented。
58+
**proxy**: {Boolean}, default true. webpack compiled in a separate service inside, you can use project domain and port access static resources。
59+
**webpackConfigList**: {Array}, optional, default []. native webpack config.
60+
**webpackConfigFile**: {String}, optional, you must set when you easywebpack config file is not in the project root directory。
61+
62+
63+
### webpack native configuration
64+
65+
- if you write one native webpack config `${app_root}/build/webpack.config.js`, you can use like this:
66+
67+
```js
68+
// {app_root}/config/config.default.js
69+
exports.webpack = {
70+
webpackConfigList: [require('../build/webpack.config.js')]
71+
};
72+
```
73+
74+
- if you use easywebpack solution, you can use like this:
75+
76+
default read `webpack.config.js` file under the project root directory.
77+
78+
```js
79+
const EasyWebpack = require('easywebpack-vue');
80+
// {app_root}/config/config.default.js
81+
exports.webpack = {
82+
webpackConfigList: EasyWebpack.getWebpackConfig()
83+
};
84+
```
85+
86+
- if you use easywebpack solution, the easywebpack config file in `${app_root}/build/webpack.config.js`, you can use like this:
87+
88+
```js
89+
const EasyWebpack = require('easywebpack-vue');
90+
// {app_root}/config/config.default.js
91+
exports.webpack = {
92+
webpackConfigList: EasyWebpack.getWebpackConfig('build/webpack.config.js')
93+
};
94+
```
95+
96+
### easywebpack configuration
97+
98+
The default read `webpack.config.js` file under the project root directory.
99+
100+
```js
101+
// {app_root}/config/config.default.js
102+
exports.webpack = {
103+
webpackConfigFile: 'build/webpack.config.js', // easywebpack config file path
104+
};
105+
```
106+
107+
53108
see [config/config.default.js](config/config.default.js) for more detail.
54109

55110
## Customise

agent.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module.exports = agent => {
1212
if (Utils.isUseMultProcess(agent.baseDir, config)) {
1313
new MultProcessWebpackServer(agent, config).start();
1414
} else {
15-
config.useDll = config.useDll || false;
1615
new WebpackServer(agent, config).start();
1716
}
1817
});

lib/build.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ const WebpackTool = require('webpack-tool');
44
const utils = require('./utils');
55

66
exports.dll = (config, option, callback) => {
7-
if (config && config.useDll === false) {
8-
callback();
9-
} else {
7+
const cliConfig = utils.getWebpackConfigJSON(option.baseDir, config);
8+
if (cliConfig && cliConfig.dll) {
109
const webpackTool = new WebpackTool();
11-
const webpackConfig = utils.getWebpackConfig(config, { onlyDll: true, baseDir: option.baseDir });
10+
const webpackConfig = utils.getWebpackConfig(config, { onlyDll: true, baseDir: option.baseDir
11+
});
1212
if (webpackConfig) {
1313
webpackTool.build(webpackConfig, {}, callback);
1414
} else {
1515
callback();
1616
}
17+
} else {
18+
callback();
1719
}
1820
};

lib/utils.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,29 @@ exports.requireModule = (module, baseDir) => {
3535
}
3636
};
3737

38-
exports.isUseMultProcess = (baseDir, config) => {
38+
exports.getWebpackConfigJSON = (baseDir, config) => {
3939
const filename = config.webpackConfigFile || 'webpack.config.js';
4040
const webpackConfigFile = path.isAbsolute(filename) ? filename : path.join(baseDir, filename);
41+
if (fs.existsSync(webpackConfigFile)) {
42+
return require(webpackConfigFile);
43+
}
44+
return null;
45+
};
46+
47+
exports.isUseMultProcess = (baseDir, config) => {
4148
if (config && config.webpackConfigList.length) {
4249
return false;
4350
}
44-
if (fs.existsSync(webpackConfigFile)) {
45-
const config = require(webpackConfigFile);
46-
if (config.type === undefined || config.target === undefined) {
51+
const cliConfig = exports.getWebpackConfigJSON(baseDir, config);
52+
if (cliConfig) {
53+
if (cliConfig.type === undefined || cliConfig.target === undefined) {
4754
return true;
4855
}
49-
if (Array.isArray(config.type) && config.type.length > 1) {
56+
if (Array.isArray(cliConfig.type) && cliConfig.type.length > 1) {
5057
return true;
5158
}
5259

53-
if (Array.isArray(config.target) && config.target.length > 1) {
60+
if (Array.isArray(cliConfig.target) && cliConfig.target.length > 1) {
5461
return true;
5562
}
5663
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "egg-webpack",
3-
"version": "3.2.7",
3+
"version": "3.2.8",
44
"description": "webpack dev server plugin for egg, support read file in memory and hot reload.",
55
"eggPlugin": {
66
"name": "webpack",

0 commit comments

Comments
 (0)