output.polyfill
- Type:
'entry' | 'usage' | 'off' - Default:
'off'
Controls the polyfill injection mode.
See Polyfill Mode for more details.
Install core-js
When you enable polyfill injection, make sure core-js v3 is installed in your project, which is a popular polyfill library for JavaScript.
Optional value
usage
With output.polyfill set to 'usage', Rsbuild checks the APIs used in each file compiled by SWC and injects the polyfills needed by the target browsers. Files not compiled by SWC are not checked. Use source.include to compile additional files.
entry
With output.polyfill set to 'entry', Rsbuild injects polyfills in each entry file. The injected core-js polyfills are selected for the target browsers, regardless of which APIs your code uses. This can increase bundle size.
It should be noted that when you bundle page with Web Workers, the entry mode is not applicable to Web Workers because the Web Workers thread is isolated from the main thread (page), and the usage mode can be used at this time.
off
With output.polyfill set to 'off', Rsbuild doesn't inject polyfills. You need to handle code compatibility yourself.

