babel-polyfill-plugin-corejs2
v1.0.1
Published
babel-polyfill-plugin-corejs2 supports the usage-pure, usage-global, and entry-global methods. When entry-global is used, it replaces imports to core-js.
Readme
Babel Polyfill Plugin CoreJS2
babel-polyfill-plugin-corejs2 is a Babel plugin intended to provide CoreJS 2 polyfills for JavaScript features that may not be available in older runtime environments.
Installation
npm install babel-polyfill-plugin-corejs2Or with Yarn:
yarn add babel-polyfill-plugin-corejs2Usage
Add the plugin to your Babel configuration:
{
"plugins": [
"babel-polyfill-plugin-corejs2"
]
}For a .babelrc file:
{
"presets": [],
"plugins": [
"babel-polyfill-plugin-corejs2"
]
}Why Use It?
The plugin can help applications that need compatibility with environments that do not natively support certain modern JavaScript features.
CoreJS 2 provides polyfills for features such as:
PromiseMapSetWeakMapSymbolArray.fromObject.assign- Various ES6/ES7 APIs
Important Note
CoreJS 2 is an older polyfill library. For new projects, consider using a current Babel/CoreJS setup based on core-js 3 instead.
For example:
npm install core-js@3A modern Babel configuration can use:
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3
}
]
]
}Compatibility
This package is primarily useful when maintaining an existing project that depends on the CoreJS 2 ecosystem. Before introducing it into a new application, verify that its dependencies and Babel version are compatible with your project.
Example Project Structure
my-project/
├── src/
│ └── index.js
├── .babelrc
├── package.json
└── README.md.babelrc
{
"plugins": [
"babel-polyfill-plugin-corejs2"
]
}src/index.js
const values = new Set([1, 2, 3]);
console.log(values);Development
Install dependencies:
npm installRun your project's build or Babel command according to its configuration.
License
Check the package's published npm metadata or repository for the applicable license and licensing terms.
Recommendation
If you are starting a new Node.js project, I would generally avoid adding babel-polyfill-plugin-corejs2 unless you specifically need CoreJS 2 compatibility. For a modern application, Babel + core-js 3 is the preferable direction.
