webpack < 5 used to include polyfills for node.js core modules by default
时间: 2024-06-08 16:12:50 浏览: 171
node-polyfill-webpack-plugin:Webpack中的Polyfill Node.js核心模块
4星 · 用户满意度95%
Yes, that's correct. In versions of webpack before 5, it used to include polyfills for Node.js core modules by default. This means that when bundling your code for the browser, webpack would automatically include polyfills for modules such as `fs`, `path`, `crypto`, and others, which are common in Node.js but not available in the browser environment.
Including these polyfills allowed developers to write code that used Node.js core modules without worrying about compatibility issues when running the code in the browser. However, this approach also added unnecessary code to the final bundle, increasing its size.
Starting from webpack 5, the default behavior has changed. Webpack no longer includes polyfills for Node.js core modules by default. Instead, it encourages developers to use conditional imports or other techniques to handle the use of these modules in a browser-compatible way.
This change was made to improve performance and reduce bundle size, as including unnecessary polyfills can have a negative impact on both. However, if you still need to include polyfills for Node.js core modules in your webpack 5 configuration, you can do so using plugins or other customizations.
阅读全文