Skip to content

richardscarrott/require-error-handler-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • Update bundle-loader to support new require.ensure syntax.
  • Work out how to alias the loader to 'bundle' and carry across query params.
  • 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

About

Adds error callback to require.ensure and AMD require calls.

Resources

License

Stars

Watchers

Forks

Packages

No packages published