event-callback-webpack-plugin
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -0,1 +1,7 @@ | ||
# 1.1.0 | ||
- Added: support multiple events. | ||
- Chore: minimum required `nyc` version is now `^10.0.0`. | ||
- Chore: minimum required `eslint-plugin-itgalaxy` version is now `^30.0.0`. | ||
# 1.0.1 | ||
@@ -2,0 +8,0 @@ |
@@ -12,15 +12,27 @@ 'use strict'; | ||
var EventCallbackWebpackPlugin = function () { | ||
function EventCallbackWebpackPlugin(event, callback) { | ||
function EventCallbackWebpackPlugin(events) { | ||
_classCallCheck(this, EventCallbackWebpackPlugin); | ||
if (!event) { | ||
throw new Error('Require `event` argument'); | ||
if (Array.isArray(events)) { | ||
throw new Error('Option `events` should be `object` or `string`'); | ||
} | ||
if (!callback) { | ||
throw new Error('Require `callback` argument'); | ||
if (!events || Object.keys(events).length === 0) { | ||
throw new Error('Option `events` should not be empty'); | ||
} | ||
this.event = event; | ||
this.callback = callback; | ||
if (typeof events === 'string') { | ||
if ((arguments.length <= 1 ? 0 : arguments.length - 1) === 0) { | ||
throw new Error('Require `callback` argument'); | ||
} | ||
this.events = {}; | ||
this.events[events] = arguments.length <= 1 ? undefined : arguments[1]; | ||
} else { | ||
if ((arguments.length <= 1 ? 0 : arguments.length - 1) > 0) { | ||
throw new Error('Don\'t pass second argument if first argument is `object`'); | ||
} | ||
this.events = events; | ||
} | ||
} | ||
@@ -33,4 +45,12 @@ | ||
compiler.plugin(this.event, function () { | ||
return _this.callback.apply(_this, arguments); | ||
Object.keys(this.events).forEach(function (event) { | ||
var callback = _this.events[event]; | ||
if (typeof callback !== 'function') { | ||
throw new Error('Option `callback` should be a function'); | ||
} | ||
compiler.plugin(event, function () { | ||
return callback.apply(undefined, arguments); | ||
}); | ||
}); | ||
@@ -37,0 +57,0 @@ } |
{ | ||
"name": "event-callback-webpack-plugin", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Webpack plugin that gives ability to add callback after webpack event", | ||
@@ -50,3 +50,3 @@ "keywords": [ | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-itgalaxy": "^28.0.0", | ||
"eslint-plugin-itgalaxy": "^30.0.0", | ||
"eslint-plugin-jsx-a11y": "^3.0.0", | ||
@@ -60,3 +60,3 @@ "eslint-plugin-lodash": "^2.1.0", | ||
"npm-run-all": "^3.0.0", | ||
"nyc": "^9.0.0", | ||
"nyc": "^10.0.0", | ||
"package-schema": "^1.0.0", | ||
@@ -63,0 +63,0 @@ "remark-cli": "^2.0.0", |
@@ -7,2 +7,4 @@ # event-callback-webpack-plugin | ||
Add callbacks to webpack events. | ||
## Install | ||
@@ -17,11 +19,11 @@ | ||
```js | ||
const EventCallbackWebpackPlugin = require('event-callback-webpack-plugin').default; | ||
import EventCallbackWebpackPlugin from 'event-callback-webpack-plugin'; | ||
module.exports = { | ||
export default { | ||
plugins: [ | ||
new EventCallbackWebpackPlugin('done', () => { | ||
console.log('Hello World!'); | ||
console.log('Hello `done`!'); | ||
}) | ||
] | ||
} | ||
}; | ||
``` | ||
@@ -36,4 +38,13 @@ | ||
plugins: [ | ||
new EventCallbackWebpackPlugin('done', () => { | ||
console.log('Hello World!'); | ||
new EventCallbackWebpackPlugin({ | ||
emit: (compilation, callback) => { | ||
console.log('Hello `emit`!'); | ||
return callback(); | ||
}, | ||
'after-emit': (compilation, callback) => { | ||
console.log('Hello `after-emit`!'); | ||
return callback(); | ||
} | ||
}) | ||
@@ -46,4 +57,4 @@ ] | ||
- `event` - (require) webpack event. | ||
- `callback` - (require) callback function. | ||
- `events` - (require) `string` or `object` webpack events. | ||
- `callback` - (optional) callback function. | ||
@@ -50,0 +61,0 @@ ## Contribution |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8562
46
64