From 592fc62dfcea8bf532eaa1fdab6ca5e39e34ff05 Mon Sep 17 00:00:00 2001 From: Zac Kienzle Date: Sun, 22 Nov 2026 17:59:56 +1000 Subject: [PATCH] fix: publish one ES module per source file Since 3.0.2 the package entry is one bundled file, so sideEffects: false no longer lets a bundler drop unused distributions, and a bundler has to prove each top-level call removable instead. Rollup's output.preserveModules writes dist/esm with one file per source module, as 3.0.1 published src/, and the package entry points there. dist/d3-random.mjs and the UMD builds are unchanged. Bundling an import of randomInt alone with `esbuild --bundle --minify` gives 3.3 kB before and 214 B after. --- package.json | 6 +++--- rollup.config.js | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index da1e122..a12df69 100644 --- a/package.json +++ b/package.json @@ -23,13 +23,13 @@ "dist/**/*.js", "dist/**/*.mjs" ], - "module": "dist/d3-random.mjs", - "main": "dist/d3-random.mjs", + "module": "dist/esm/index.js", + "main": "dist/esm/index.js", "jsdelivr": "dist/d3-random.min.js", "unpkg": "dist/d3-random.min.js", "exports": { "umd": "./dist/d3-random.min.js", - "default": "./dist/d3-random.mjs" + "default": "./dist/esm/index.js" }, "sideEffects": false, "devDependencies": { diff --git a/rollup.config.js b/rollup.config.js index d05a0a3..a4059bb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -39,6 +39,14 @@ function config(options) { } export default [ + // One file per module, so that sideEffects: false lets bundlers drop unused distributions. + config({ + output: { + dir: "dist/esm", + format: "es", + preserveModules: true + } + }), config({ output: { file: `dist/${meta.name}.mjs`,