-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
What problem does this address?
Currently, simple scripts like wp-hooks depend on wp-polyfill, even when they don't seem to make use of any of the features that are currently present in wp-polyfill:
The list of polyfilled features in `wp-polyfill` as of issue creation
es.array.push
es.array.to-reversed
es.array.to-sorted
es.array.to-spliced
es.array.with
es.map.group-by
es.object.group-by
es.promise.with-resolvers
es.regexp.flags
es.string.is-well-formed
es.string.to-well-formed
es.typed-array.to-reversed
es.typed-array.to-sorted for
es.typed-array.with
web.dom-exception.stack
web.structured-clone
web.url.can-parse
web.url-search-params.delete
web.url-search-params.has
web.url-search-params.size
As far as I can tell, the dependency on wp-polyfill comes from a hardcoded boolean in tools/webpack/packages.js:
new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ),This approach is problematic, since it can lead to the fairly large wp-polyfill being loaded in the head to support simple scripts like wp-hooks and wp-i18n.
What is your proposed solution?
At a high level, it seems that DependencyExtractionWebpackPlugin should be able to determine on its own whether polyfills are needed, and the injectPolyfill configuration option should be dropped (or perhaps turned into an optional override).
Perhaps the plugin could look for core-js imports, as it currently does for WordPress ones? Though I'm not sure if it runs before or after Babel.
Alternatively, we could hardcode a list of excluded packages, but that would involve some amount of error-prone maintenance.