-
Notifications
You must be signed in to change notification settings - Fork 215
Correct way to polyfill v1.0 in the browser (webpack) #118
Comments
We're preparing an integration with the polyfill service, I think that it'll be a way to uses in the browser. See also: |
Thanks, interesting - will this change ship with |
polyfill-service v1.5.0 RC is now on QA. It depends on intl.js v1.0.0-rc-4. You're able to try it via qa.polyfill.io. |
great thanks! however I'm not sure yet how |
@gpbl once the polyfill service supports Intl, you should not try to bundle up the polyfill with your app code, instead you should load the polyfill and patch the runtime only when it is absolutely needed, and that's what the polyfill service from FT does. This concept extends to any polyfill :) |
...so the polyfill service doesn't actually help with webpack, it is meant to replace it. But as @xjamundx writes, webpack already provides the way to apply the polyfill when needed. Why should I add a new library or depend from an external service? I understand this is not the way the library authors think the polyfill has to be applied, yet it has been always possible to bundle it with webpack. However, differently from the versions < v1, we must both load |
Apply !== Load/Parsing, are you going to penalize all your users (even those that are running in browsers with support for Intl), which could be +90% in some cases (for desktop apps)? Polyfills are optional patches for runtimes, they have nothing to do with app code, they should not be bundled with app code IMO. |
Ah! I see the misunderstanding. No, this is not the case. Look to this: if (!window.Intl) {
// hello safari
require.ensure(['intl/Intl'], (require) => {
window.Intl = require('intl/Intl')
runMyApp()
}, "IntlBundle");
}
else {
// hello chrome, ie, etc.!
runMyApp()
} it reads: if
We don't bundle This is different from the polyfill alone, which is loaded (but not applied) even on browsers that don't require it. Code splitting is one of the main reasons to choose webpack as module bundler, that's why I insist |
Ok, that makes sense. We can add the same configuration we use in react-intl, to define a custom way to require intl, and the locale data when using browserify/webpack, that should be easy. Will try to get that flush soon. |
Some progress here #121 |
fixes #118: ignoring the inclusion of all locale date when bundling the polyfill with browserify/webpack.
Thanks! Very happy with |
Hi Im using React-Intl, and it cannot find window.intl I think ? Any ideas on what I am doing incorrectly.. Thanks |
@donnrri are you using the polyfill service? |
@gpbl Ciao Giampaolo, have you got an example for angular
Above is my startup script.
I need that the intl chunk is downloading before app start. Any idea? |
I've got my code working with v1.0 rc4 π yet I'm not sure why it works. My goal is to require the polyfill using webpack's code splitting, loading the locale-data after Intl has been polyfilled β e.g. in Safari.
Before v1.0 I was doing:
Now I see the package to load has been moved in
intl/dist/Intl
. However just requiring it does not add aIntl
global:Looking to the objects exported from
dist/Intl
i seeIntl
andIntlPolyfill
. So I wrote the following, but loading the locale-data throws aIntlPolyfill is not defined
:Instead, everything works fine when I do:
I'm using it right? What is the difference between the exported
IntlPolyfill
andIntl
? Why is locale-data requiringIntlPolyfill
(I was expecting it augmentingIntl
)? I looked into the issues and PRs but couldn't find any help.Thanks!
The text was updated successfully, but these errors were encountered: