Search code examples
webpackbabeljsbabel-polyfill

Babel-standalone exist in production bundle


After production-mode build there is a babel-standalone module in my bundle. But i never installed this babel-standalone manually. And it doesn't exist in package.json either. But i installed the babel-polyfill in this project, does babel-standalone come with babel-polyfill? How can i remove this module from bundle so that can reduce the size of production bundle?

The screen shot from webpack-bundle-analyzer is like:

enter image description here


Solution

  • babel-polyfill doesn't depend on babel-standalone. There is something else that is importing it. You can run npm ls babel-standalone or yarn why babel-standalone to see why it's installed.

    After figuring out why babel-standalone is included in your bundle, if you are sure that neither you nor your dependencies need it (it's used to compile JS code on-the-fly in the browser rather than at build time), you can remove it by using Webpack's null-loader:

      rules: [
        {
          // Adjust this path to match the path of the imported babel-standalone file
          test: path.resolve(__dirname, 'node_modules/babel-standalone/babel.js'),
          use: 'null-loader',
        },
      ]