js-temporal / temporal-polyfill

Polyfill for Temporal (under construction)
ISC License
528 stars 28 forks source link

Limited tree-shaking when Temporal is imported but not used #286

Closed federicocarboni closed 5 months ago

federicocarboni commented 5 months ago

Bundlers are not able to remove the temporal polyfill when it is imported but not used. This produces large bundles even when Temporal functionality is not used.

import {Temporal} from "@js-temporal/polyfill";

export function usesTemporal() {
  // Anything with Temporal
  return Temporal.PlainDateTime.from("1970-01-01");
}

export function notUsingTemporal() {
  return 42;
}

Now even if the user of the library only imports notUsingTemporal a large amount of code from the temporal polyfill is included anyway.

This is very important for library authors who want to use Temporal but allow it to be tree-shaken out if not necessary.

federicocarboni commented 5 months ago

Fixed in #287