Removes webpack-specific functions from JavaScript code.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.babelrc
.eslintrc.yml
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
package.json

README.md

babel-plugin-remove-webpack

Dependency Status devDependency Status Build Status Npm Version License Badges

Removes webpack-specific functions from JavaScript code.

require.ensure

require.ensure is replaced with an IIFE.

// Before
require.ensure(['a', 'b', 'c'], function (require) {
  const a = require('a');
  const b = require('b');
  const c = require('c');
});

// After
(function () {
  const a = require('a');
  const b = require('b');
  const c = require('c');
})();

require.include

require.include is removed entirely.

// Before
require.include('a');

// After

Motivation

require.ensure and require.include are great for code splitting; however, they can cause issues when writing universal JavaScript. The typical solution is to use synchronous shims. In order for webpack code splitting to work properly these shims have to be defined in each file where they are used.

This plugin makes it possible to universally run code which uses webpack-specific functions without having to manually polyfill those functions.

Usage Notes

This plugin should not be used as a part of a build with webpack, otherwise code splitting will stop working. The intended usage is with the babel-register package or some other build with babel that specifically targets node. Usage as such will remove require.ensure and require.include calls as shown above so you can run your client code on the server without shims.

License

MIT