require-error-handler-webpack-plugin
v0.0.2
Published
Adds error callback to require.ensure and AMD require calls
Downloads
663
Maintainers
Readme
require-error-handler-webpack-plugin
Adds error callback to require.ensure and AMD require calls.
NOTE: Split point error handling was landed in Webpack 2 via
System.import
so I'd strongly advise against using this plugin.
Usage
var requireErrorHandlerPlugin = require('require-error-handler-webpack-plugin');
var JsonpMainTemplatePlugin = require('webpack/lib/JsonpMainTemplatePlugin');
{
plugins: [
// `JsonpMainTemplatePlugin` is neccesary as it must be monkey patched.
new requireErrorHandlerPlugin.JsonpErrorHandlerPlugin(JsonpMainTemplatePlugin),
new requireErrorHandlerPlugin.RequireEnsureErrorHandlerPlugin(),
new requireErrorHandlerPlugin.AMDRequireErrorHandlerPlugin()
]
}
JsonpErrorHandlerPlugin
Adds an error callback to the jsonp transport method that is called when a chunk fails to load.
NOTE: This depends on the JsonpTemplatePlugin
being applied (webpack does this by default given a target of 'web' or 'node-webkit').
RequireEnsureErrorHandlerPlugin
Adds support for the following signatures:
require.ensure(['a'], function() {
// success
}, function() {
// error
}, 'a');
require.ensure(['b'], function() {
// success
}, function() {
// error
});
require.ensure(['c'], function() {
// success
}, 'c');
require.ensure(['d'], function() {
// success
});
NOTE: This depends on the RequireEnsurePlugin
being applied (webpack does this by default).
AMDRequireErrorHandlerPlugin
Adds support for the following signatures:
require(['c'], function() {
// success
}, function() {
// error
});
require(['b'], function() {
// success
});
require(['a']);
NOTE: This depends on the AMDRequirePlugin
being applied (webpack does this by default).
BundleLoader
Adds an error callback to the bundle loader, e.g.
// Supports both immediate and lazy requires.
var bundle = require("require-error-handler-webpack-plugin/src/BundleLoader!./file.js");
bundle(function(file) {
// success
}, function() {
// errror
});
Todo
- [x] Update
bundle-loader
to support newrequire.ensure
syntax. - [ ] Work out how to alias the loader to 'bundle' and carry across query params.
- [x] Add support for default wrapper when chunks are merged
- [ ] Add support for named chunks using AMD, i.e. require(name?, deps, successCallback?, errorCallback?)
- [ ] Work out how this can occur and support it.
- [ ] Remove hacks required to get this to work by potentially requesting changes to webpack to make it easier to hook in.
Related
- https://github.com/webpack/webpack/issues/758
- https://github.com/richardscarrott/webpack
- https://github.com/webpack/webpack/pull/785
- https://github.com/webpack/webpack/pull/692