Modules — ESM-first, tree-shakable
Import only what you use. package.json is sideEffects: false with explicit subpath exports.
Exports map
json — package.json
{
"type": "module",
"sideEffects": false,
"exports": {
".": { "import": "./dist/index.js", "require": "./dist/index.cjs" },
"./dom": { "import": "./dist/dom.js" },
"./http": { "import": "./dist/http.js" },
"./events": { "import": "./dist/events.js" },
"./animation": { "import": "./dist/animation.js" },
"./storage": { "import": "./dist/storage.js" },
"./ui": { "import": "./dist/ui.js" },
"./observers": { "import": "./dist/observers.js" },
"./utils": { "import": "./dist/utils.js" }
}
}Usage
js
// Full (still tree-shakable via named imports)
import { F } from "flash.js";
// Only HTTP — bundler drops dom/ui/animation/storage
import { http } from "flash.js/http";
const user = await http.json("/api/user");
// Only UI
import { toast, modal } from "flash.js/ui";
toast("Hello", "success");
// Only storage
import { storage } from "flash.js/storage";
storage.set("theme", "dark");
// Attach helpers still available on F when you import from "flash.js"
import { F } from "flash.js";
F.http === http; // true — F is augmented via src/index.jsCDN / UMD
html
<script src="https://unpkg.com/flash.js/dist/flash.min.js"></script>
<script>
// Global F / Flash
F.toast("hello");
</script>dist/flash.js is the unminified UMD from flash.js:1 (single-file core). dist/flash.min.js is terser-minified. Both expose F and Flash globals.
Analysis
Vite / Rollup / esbuild will drop unused modules automatically. To verify:
bash
npm run build
# check dist/ chunks — only imported exports appear
npx vite build --debug # or rollup --config --silentThis website
The site itself imports flash.js as file:.. — see website/package.json. During dev it resolves to the local build, proving the package exports work end-to-end before publishing.