What is @babel/plugin-external-helpers?
@babel/plugin-external-helpers is a Babel plugin that allows you to use Babel's helper functions from an external source rather than including them in every file. This can help reduce the overall bundle size by avoiding duplication of helper functions across multiple files.
What are @babel/plugin-external-helpers's main functionalities?
Externalizing Babel Helpers
This configuration in your Babel setup will enable the use of external helpers. Instead of including Babel's helper functions in every file, they will be imported from an external source, reducing redundancy and potentially decreasing the bundle size.
module.exports = {
plugins: [
'@babel/plugin-external-helpers'
]
};
Using with a Custom Helper Library
You can specify a custom version of the helper library to use. This is useful if you have a specific version of Babel's helpers that you want to ensure compatibility with.
module.exports = {
plugins: [
['@babel/plugin-external-helpers', {
helperVersion: '7.0.0'
}]
]
};
Other packages similar to @babel/plugin-external-helpers
babel-plugin-transform-runtime
babel-plugin-transform-runtime is another Babel plugin that helps to avoid duplication of helper functions by using a runtime library. Unlike @babel/plugin-external-helpers, which relies on externalizing helpers, transform-runtime uses a runtime library to achieve similar goals, often leading to smaller bundle sizes and avoiding polluting the global scope.
babel-plugin-external-helpers-2
babel-plugin-external-helpers-2 is a fork of @babel/plugin-external-helpers with additional features and improvements. It aims to provide more flexibility and better performance compared to the original plugin.
@babel/plugin-external-helpers
Installation
npm install --save-dev @babel/plugin-external-helpers
Usage
Via .babelrc
(Recommended)
.babelrc
{
"plugins": ["@babel/plugin-external-helpers"]
}
Via CLI
babel --plugins @babel/plugin-external-helpers script.js
Via Node API
require("@babel/core").transform("code", {
plugins: ["@babel/plugin-external-helpers"]
});