Negotiable Paleobotanist Missions

    babel-plugin-remove-webpack

    1.1.0 • Public • Published

    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

    Install

    npm i babel-plugin-remove-webpack

    DownloadsWeekly Downloads

    3,817

    Version

    1.1.0

    License

    MIT

    Last publish

    Collaborators

    • kenpowers