Skip to content

Commit 1d84381

Browse files
Add in options for compatibility with webpack-merge
1 parent 696d1a4 commit 1d84381

2 files changed

Lines changed: 59 additions & 20 deletions

File tree

README.md

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Speed Measure Webpack Plugin
2-
3-
**_(this plugin is not yet stable, and not safe for production)_**
1+
# Speed Measure Plugin
42

53
This plugin measures your webpack build speed, giving an output like this:
64

@@ -32,15 +30,15 @@ file-loader took 7.11 seconds
3230

3331
# Getting Started
3432

35-
`npm install --save-dev speed-measure-webpack-plugin`
33+
`npm install --save speed-measure-webpack-plugin`
3634

3735
Change your webpack config from
3836

39-
```
37+
```javascript
4038
{
41-
entry: {...},
42-
output: {...},
43-
module: {...},
39+
entry: {/*...*/},
40+
output: {/*...*/},
41+
module: {/*...*/},
4442
plugins: [
4543
new MyPlugin(),
4644
new MyOtherPlugin()
@@ -50,11 +48,13 @@ Change your webpack config from
5048

5149
to
5250

53-
```
51+
```javascript
52+
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
53+
5454
{
55-
entry: {...},
56-
output: {...},
57-
module: {...},
55+
entry: {/*...*/},
56+
output: {/*...*/},
57+
module: {/*...*/},
5858
plugins: SpeedMeasurePlugin.wrapPlugins({
5959
MyPlugin: new MyPlugin(),
6060
MyOtherPlugin: new MyOtherPlugin()
@@ -64,11 +64,13 @@ to
6464

6565
Or you can also specify config:
6666

67-
```
67+
```javascript
68+
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
69+
6870
{
69-
entry: {...},
70-
output: {...},
71-
module: {...},
71+
entry: {/*...*/},
72+
output: {/*...*/},
73+
module: {/*...*/},
7274
plugins: SpeedMeasurePlugin.wrapPlugins({
7375
MyPlugin: new MyPlugin(),
7476
MyOtherPlugin: new MyOtherPlugin()
@@ -79,6 +81,38 @@ Or you can also specify config:
7981
}
8082
```
8183

84+
If you're using `webpack-merge`, then you can do:
85+
86+
```javascript
87+
// base config file
88+
const smp = new SpeedMeasurePlugin({
89+
outputFormat: "human"
90+
});
91+
92+
const finalConfig = webpackMerge(
93+
[baseConfig, envSpecificConfig].map(configGenerator =>
94+
configGenerator({
95+
smp,
96+
// other options
97+
})
98+
)
99+
);
100+
101+
// baseConfig
102+
export const baseConfig = ({ smp }) => ({
103+
plugins: smp.wrapPlugins({
104+
MyPlugin: new MyPlugin()
105+
}).concat(smp)
106+
})
107+
108+
// envSpecificConfig
109+
export const envSpecificConfig = ({ smp }) => ({
110+
plugins: smp.wrapPlugins({
111+
MyOtherPlugin: new MyOtherPlugin()
112+
})
113+
})
114+
```
115+
82116
## `outputFormat` ##
83117

84118
(default `"json"`)

index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = class SpeedMeasurePlugin {
1414

1515
this.timeEventData = {};
1616

17+
this.wrapPlugins = this.wrapPlugins.bind(this);
1718
this.getOutput = this.getOutput.bind(this);
1819
this.addTimeEvent = this.addTimeEvent.bind(this);
1920
this.apply = this.apply.bind(this);
@@ -24,6 +25,12 @@ module.exports = class SpeedMeasurePlugin {
2425

2526
const smp = new SpeedMeasurePlugin(options);
2627

28+
const wrappedPlugins = smp.wrapPlugins(plugins);
29+
30+
return wrappedPlugins.concat(smp);
31+
}
32+
33+
wrapPlugins(plugins) {
2734
if (Array.isArray(plugins)) {
2835
let i = 1;
2936
plugins = plugins.reduce((acc, p) => {
@@ -33,11 +40,9 @@ module.exports = class SpeedMeasurePlugin {
3340
}
3441
plugins = plugins || {};
3542

36-
const wrappedPlugins = Object.keys(plugins).map(
37-
pluginName => new WrappedPlugin(plugins[pluginName], pluginName, smp)
43+
return Object.keys(plugins).map(
44+
pluginName => new WrappedPlugin(plugins[pluginName], pluginName, this)
3845
);
39-
40-
return wrappedPlugins.concat(smp);
4146
}
4247

4348
getOutput() {

0 commit comments

Comments
 (0)