Skip to content

Add support for split point error handling#785

Closed
richardscarrott wants to merge 9 commits intowebpack:masterfrom
richardscarrott:master
Closed

Add support for split point error handling#785
richardscarrott wants to merge 9 commits intowebpack:masterfrom
richardscarrott:master

Conversation

@richardscarrott
Copy link
Copy Markdown

Usage

var JsonpErrorHandlerPlugin = require('webpack/lib/JsonpErrorHandlerPlugin');
var RequireEnsureErrorHandlerPlugin = require('webpack/lib/dependencies/RequireEnsureErrorHandlerPlugin');
var AMDRequireErrorHandlerPlugin = require('webpack/lib/dependencies/AMDRequireErrorHandlerPlugin');

{
    plugins: [
            new JsonpErrorHandlerPlugin(),
            new RequireEnsureErrorHandlerPlugin(),
            new AMDRequireErrorHandlerPlugin()
    ]
}

JsonpErrorHandlerPlugin

Adds an error callback to the jsonp transport method that is called when a chunk fails to load.

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
});

AMDRequireErrorHandlerPlugin

Adds support for the following signatures:

require(['a']);

require(['b'], function() {
    // success
});

require(['c'], function() {
    // success
}, function() {
    // error
});

This has been working well for me however there were a few areas which were difficult to hook into, in particular, the JsonpMainTemplatePlugin and the code is far from perfect at the moment so it'd be good to get some pointers.

@richardscarrott
Copy link
Copy Markdown
Author

I've fixed up a few issues, updated the bundle loader and moved this out into a separate plugin repo: https://github.com/richardscarrott/require-error-handler-webpack-plugin so it can be used as is.

It's still not ideal and personally I think the best solution would be to have error handling supported by default in webpack (as it adds minimal bootstrap code) rather than having to dupe so much logic in a plugin; it feels to me error handling is vital to being able to use split points in production...

@sokra
Copy link
Copy Markdown
Member

sokra commented Jun 15, 2015

I still have this in mind and it will eventually be merged into the webpack-2 branch.

ES6 adds System.import which returns a promise. This is a nice user-facing API for error handling.

@richardscarrott
Copy link
Copy Markdown
Author

Great! If you need any help let me know.

@NekR
Copy link
Copy Markdown

NekR commented Jul 26, 2015

@sokra will there be way to use it without System.import and Promises?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is here a reason why you do not check readyState for readystatechange event? before calling onComplete?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid buggy implementations of onreadystatechange in old IE (I think less than 9). It worked out nicely because webpack is already using a jsonp style callback so I just check whether it is actually installed to determine if an error has occurred.

@NekR
Copy link
Copy Markdown

NekR commented Aug 20, 2015

@sokra @richardscarrott
Hi guys, here I made little loader based on bundle-loader but with error handling improvements: https://github.com/NekR/async-module-loader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants