0

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

Nelson
  • 209
  • 2
  • 7

1 Answers1

0

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',
    },
  ]
Nicolò
  • 1,795
  • 1
  • 16
  • 16
  • Thanks for your answer! But after i run `npm ls babel-standalone`, the result is empty. I edit my question for some details. Can you help me to check a bit ? – Nelson Apr 29 '21 at 13:35
  • From the original answer I assume that the packages you were seeing was `babel-standalone` and not `@babel/standalone`. You can use `npm ls @babel/standalone` to see why it's included. – Nicolò May 07 '21 at 08:32