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

[@babel/babel-polyfill] allow use of Financial-Times/polyfill-library as polyfills-source #19

Open
nitwhiz opened this issue Mar 12, 2019 · 7 comments

Comments

@nitwhiz
Copy link

nitwhiz commented Mar 12, 2019

Feature Request

Is your feature request related to a problem? Please describe.
core-js is missing the important things. ChildNode.remove(), fetch(), XMLHttpRequest() ...

Describe the solution you'd like
possibility to use Financial-Times/polyfill-library or any other source of polyfills while keeping the possibility of useBuiltIns: 'usage', so babel-loader still only includes whats necessary.

Describe alternatives you've considered
Including a huge bundle of polyfills and/or gather the ones i need and/or have a mess of a setup of polyfilled and not polyfilled things while having half of the features polyfilled fully automatic by babel/polyfill.

Teachability, Documentation, Adoption, Migration Strategy

{
	test: /\.js$/,
	exclude: /node_modules/,
	use: {
		loader: 'babel-loader',
		options: {
			presets: [
				[
					'@babel/preset-env',
					{
						targets: {
							browsers: [
								'last 2 versions',
								'ie >= 11'
							]
						},
						useBuiltIns: 'usage',
						polyfillSource: 'Financial-Times/polyfill-library' // or somthing like this
					}
				]
			]
		}
	}
}
@babel-bot
Copy link

Hey @nitwhiz! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@zloirock
Copy link
Member

zloirock commented Mar 12, 2019

Just interesting, how you are imagining it? polyfill-library does not support ES or commonjs modules, just files concatenation. It was a reason why some time ago core-js was not added to polyfill-service / polyfill-library as a polyfills source.

@nitwhiz nitwhiz changed the title allow use of Financial-Times/polyfill-library as polyfills-source [@babel/babel-polyfill] allow use of Financial-Times/polyfill-library as polyfills-source Mar 12, 2019
@nitwhiz
Copy link
Author

nitwhiz commented Mar 12, 2019

polyfill-library has all the meta information for their polyfills. like detection for when to apply them and everything. just in a different format. I suggest the black magic @babel/babel-polyfill is using to detect that I used a Promise and @babel/preset-env is set to "IE >= 11", so it needs to polyfill Promise would work for stuff like ChildNode.remove or fetch. Retrieving the actual polyfill wouldn't be much different.

@zloirock
Copy link
Member

polyfill-library has all the meta information for their polyfills. like detection for when to apply them and everything. just in a different format.

That's perfect and really useful. But @babel/preset-env with useBuiltIns: usage / entries just add imports of required polyfills as commonjs modules. It can't work with polyfill-library.

@nitwhiz
Copy link
Author

nitwhiz commented Mar 13, 2019

So what's the supposed way to include custom polyfills? The main thing I'm after is the useBuiltIns:usage feature so I don't need to worry about polyfills and they get done from alone. How to accomplish this with other polyfills. Can I provide more polyfills in the format core-js is using and make @babel/preset-env use them? If yes - how?

The main goal is to keep my head free from thinking about "does this work?" "do i need to check if XMLHttpRequest exists?" - it would be nice to just write ES6 code with standards the majority (aka chrome) of browsers accept and having stuff that won't work on browsers in my browserlist transpiled to something that works from alone.

@zloirock
Copy link
Member

zloirock commented Mar 13, 2019

Just direct import of polyfills, I don't see any other way. I don't know anyone package which can provide required polyfills in the required format (ES or commonjs modules for each feature).

I'm thinking about adding polyfills for a serious part of web standards to core-js in the future since now we have tools like preset-env and runtime. However, if it will be done - it will be done not soon.

@nitwhiz
Copy link
Author

nitwhiz commented Mar 14, 2019

Nah I mean like providing them in the correct format. I would like to provide the polyfills I need in the correct format myself so babel will pick them up.

@nicolo-ribaudo nicolo-ribaudo transferred this issue from babel/babel May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants