Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Polyfill #907

Open
lvzegeng opened this issue Oct 29, 2021 · 3 comments
Open

add Polyfill #907

lvzegeng opened this issue Oct 29, 2021 · 3 comments

Comments

@lvzegeng
Copy link

I want to add Polyfill to new syntax such as Object.assign when packaging, for example, add useBuiltIns:'entry' to the corresponding babel configuration. What should I do, create a new babel configuration file, if so, what is the default babel configuration of the microbundle? I can modify it based on this

@developit
Copy link
Owner

Microbundle's babel configuration is generated here:

useBuiltIns: false,

useBuiltIns:'entry' is not supported because it modifies the global runtime environment, which is something libraries generally should avoid doing. For Object.assign, you could have Babel transpile to an inline helper that would avoid modifying the Object global:
https://www.npmjs.com/package/@babel/plugin-transform-object-assign

@lvzegeng
Copy link
Author

lvzegeng commented Oct 29, 2021

Not only Object.assign, but also other new APIs, such as Iterator, Generator, Set, Maps, Proxy, Reflect, Symbol, Promise and other objects. I think I should use "useBuiltIns": "usage", how should I modify the configuration now to achieve it. Just create a new babel.config.json file as follows, this will completely overwrite or merge the default configuration:

{
   "presets": [
     [
       "@babel/preset-env",
       {
         "useBuiltIns": "usage",
         "corejs": 3,
       }
     ]
   ],
   "plugins": [
     ["@babel/plugin-transform-runtime", {
       "corejs": 3
     }]
   ]
}

@developit
Copy link
Owner

@lvzegeng it will overwrite the default configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants