lib.externalHelpers
- Type:
boolean - Default:
false
Whether to import SWC helper functions from @swc/helpers instead of inlining them.
By default, the output JavaScript file may depend on helper functions to support the target environment or output format, and these helper functions will be inlined in the file that requires it.
When externalHelpers set to true, the output JavaScript will import helper functions from the external module @swc/helpers. This helps reduce duplicate helper code in the final bundles, and reduces the bundle size.
Make sure to declare and install @swc/helpers in dependencies field of package.json.
Example
Take the following code as an example:
When externalHelpers is disabled, the output JavaScript will inline helper functions.
Below is the output JavaScript file, the highlighted code is the inlined helper functions:
When externalHelpers is enabled, the output JavaScript will import helper functions from the external module @swc/helpers.
Below is the output JavaScript file, the highlighted code is importing helper functions:
