node-wpapi
node-wpapi copied to clipboard
Edge, IE11 broken. Invalid bundling and exports.
Currently bundling for Webpack environments / module environments is broken. In the Webpack build the library is build and transpiled - although in package.json it only points to the root (unstranspiled) /wpapi.js file. This is okay for most modern browsers as - only by chance - the features are supported.
Although this is not the case for Edge and IE11 both not supporting the object rest spread operator.
In summary the build is essentially broken for browsers environments - node works.
This long standing issue: https://github.com/WP-API/node-wpapi/issues/426 outlines the case with specific errors.
I have written up a PR that addresses these issues and also allows support for more environments, which is logical considering this library claims to be isomorphic - which is actually not the case at present. Also claims IE11 and edge support which is also not the case.
In the end i abandoned the PR https://github.com/WP-API/node-wpapi/pull/439 as its going to take significant work to refactor the library. Id be happy to do it, just need assurance that this would be accepted first.
Workaround for those Webpack / bundler users who want support for Edge and IE 11 you can simply add the "browser" bundle (umd) as an external dependancy. Bundling it via package.json (node_modules) will break your build in IE and Edge.
Webpack e.g.
/**
* Webpack config object
* @return {Object}
*/
module.exports = (env, argv) => {
// ...
externals: {
wpapi: 'WPAPI'
},
// ...
};
Then import as usual:
import WPAPI from "wpapi";
:-(
My suggestion to the authors would be to write the library in ES then transpile to CJS and UMD. That way we are working from best case to worst case, smallest footprint.
Workaround for those Webpack / bundler users who want support for Edge and IE 11 you can simply add the "browser" bundle (umd) as an external dependancy. Bundling it via
package.json(node_modules) will break your build in IE and Edge.
If you want to avoid editing the Webpack config and/or including it using a script tag you can also import the browser bundle directly:
import WPAPI from 'wpapi/browser/wpapi.min';
That works although not a great idea as it raises other issues