diff --git a/AGENTS.md b/AGENTS.md index 5dada4c5a..93f5d0fa5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -331,6 +331,9 @@ Vite 8 / Rolldown specifics baked into `vite.config.ts` (do not "simplify" these - Externals are regexes (`^dep(\/.+)?$`) so **subpath** imports (`dayjs/locale/de`) stay external; otherwise CJS `require()` glue leaks into the ESM output - No minification, sourcemaps on, target from `tsconfig.lib.json` (`es2020`), all deps/peerDeps externalized - Rolldown's strict CJS interop means default-imported CJS deps may need `.default` unwrapping at the call site +- `preserveModules` is on for the **ESM output only**, so `dist/es` mirrors `src` one file per module. Consumer bundlers drop whole unused modules first (guided by our `sideEffects` field) and only then attempt statement-level elimination — a single merged chunk leaves them nothing to drop. CJS stays chunked, since consumers do not tree-shake CJS +- `emptyOutDir` stays `false` because the four parallel build steps share `dist/`; `yarn build` already wipes it up front via `yarn clean` +- **`sideEffects` in `package.json` is load-bearing.** With one ESM file per module, consumer bundlers drop modules individually, so any module that runs code at import time must be listed there or it can be deleted out from under a consumer. Today that is `i18n/Streami18n` and `context/TranslationContext` (both call `Dayjs.extend` / `Dayjs.updateLocale` at module scope). Add an entry whenever you introduce module-level side effects ## Styling architecture diff --git a/package.json b/package.json index 858af3924..3bf9afb7b 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,8 @@ }, "sideEffects": [ "*.css", - "./dist/i18n/Streami18n.js" + "./dist/es/i18n/Streami18n.mjs", + "./dist/es/context/TranslationContext.mjs" ], "keywords": [ "chat", @@ -233,11 +234,6 @@ "built": true } }, - "browserslist": [ - ">0.2%", - "not ie <= 11", - "not op_mini all" - ], "packageManager": "yarn@4.15.0", "workspaces": [ "examples/*" diff --git a/vite.config.ts b/vite.config.ts index 633485c58..361aa9ebe 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -24,6 +24,7 @@ export default defineConfig({ 'mp3-encoder': resolve(__dirname, './src/plugins/encoders/mp3.ts'), }, }, + // `yarn build` already wipes dist up front via `yarn clean` emptyOutDir: false, outDir: 'dist', minify: false, @@ -43,6 +44,11 @@ export default defineConfig({ chunkFileNames: `${dir}/[name].[hash].${extension}`, entryFileNames: `${dir}/[name].${extension}`, hashCharacters: 'hex', + // Emit the ESM build as one file per source module. Consumer bundlers + // drop whole modules (guided by our package.json `sideEffects`) before + // they attempt statement-level elimination. The CJS build stays chunked, + // as CJS is not tree-shaken by consumers either way. + preserveModules: format === 'es', }; }), },