alphagov / govuk-frontend

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.
https://frontend.design-system.service.gov.uk/
MIT License
1.18k stars 325 forks source link

Polyfill imports can't be treeshaken #710

Closed NickColley closed 6 years ago

NickColley commented 6 years ago

When we import polyfills they're global.

Since a build system can't know where they're used, it can't make a decision to include it or not.

You can see an example of this here:

https://github.com/alphagov/govuk-frontend/blob/de2b8db0dcc71da3d8be2d0ad2a4f0b5b728dbb6/src/components/checkboxes/checkboxes.js#L1

A potential solution would be to have a function that polyfills return that can be called.

import polyfillBind from '../../vendor/polyfills/Function/prototype/bind'
polyfillBind()
NickColley commented 6 years ago

Just realised this is only a problem if using the 'all' entry point. Which currently doesnt allow a destructured import.

So will close for now, may re-open if we decide to allow a destructured import.

NickColley commented 6 years ago

We now encourage a destructured import so this is an issue

NickColley commented 6 years ago

Actually, let's focus on ES6 modules tree shaking before this... Will add a comment to that instead.