Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
perf(client): stop bundling every dayjs plugin twice
Elian Doran1feb20edba79
diff --git a/packages/commons/src/lib/dayjs.ts b/packages/commons/src/lib/dayjs.tsindex 09fac0f5ee..4d1afbc94b 100644--- a/packages/commons/src/lib/dayjs.ts+++ b/packages/commons/src/lib/dayjs.ts@@ -1,14 +1,10 @@import { default as dayjs, type Dayjs } from "dayjs";-import "dayjs/plugin/advancedFormat";-import "dayjs/plugin/duration";-import "dayjs/plugin/isBetween";-import "dayjs/plugin/isoWeek";-import "dayjs/plugin/isSameOrAfter";-import "dayjs/plugin/isSameOrBefore";-import "dayjs/plugin/quarterOfYear";-import "dayjs/plugin/relativeTime";-import "dayjs/plugin/utc";+// Loads the dayjs plugin type augmentations without putting their bare import specifiers in the+// runtime module graph (see dayjs_augmentations.ts for the why). This must be a type-only+// re-export rather than a type-only import, so that it survives declaration emit and the+// augmentations also reach consumers of the compiled .d.ts files.+export type * from "./dayjs_augmentations.js";//#region Pluginsimport advancedFormat from "dayjs/plugin/advancedFormat.js";diff --git a/packages/commons/src/lib/dayjs_augmentations.ts b/packages/commons/src/lib/dayjs_augmentations.tsnew file mode 100644index 0000000000..a81d18637e--- /dev/null+++ b/packages/commons/src/lib/dayjs_augmentations.ts@@ -0,0 +1,19 @@+/*+ * dayjs declares the plugin typings (and the Dayjs interface augmentations) under the suffix-less+ * ambient module names, which bundler-resolution consumers (e.g. the client) can only load through+ * these bare specifiers. The runtime imports in dayjs.ts must use the .js suffix instead, to+ * satisfy nodenext module resolution.+ *+ * This module exists so that the bare specifiers stay out of the runtime module graph: dayjs.ts+ * pulls it in with a type-only import, which is erased from the emitted JavaScript. Importing it+ * as a regular module would make Vite bundle every plugin twice (once per specifier spelling).+ */+import "dayjs/plugin/advancedFormat";+import "dayjs/plugin/duration";+import "dayjs/plugin/isBetween";+import "dayjs/plugin/isoWeek";+import "dayjs/plugin/isSameOrAfter";+import "dayjs/plugin/isSameOrBefore";+import "dayjs/plugin/quarterOfYear";+import "dayjs/plugin/relativeTime";+import "dayjs/plugin/utc";