Skip to content
Removes webpack-specific functions from JavaScript code.
JavaScript
Branch: master
Clone or download
knpwrs Merge pull request #22 from knpwrs/greenkeeper/eslint-4.1.0
Update eslint to the latest version 🚀
Latest commit dc239cf Jun 24, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Add support for arrow function Feb 22, 2016
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

You can’t perform that action at this time.