Package structure
Each Temelj package follows a consistent structure:Package layout
Package exports
All Temelj packages use the
.mjs extension and "type": "module" to ensure they’re treated as ES modules by all tools.Vite
Vite works with Temelj packages out of the box with minimal configuration.Basic configuration
vite.config.ts
Library mode
When building a library that depends on Temelj:vite.config.ts (library)
Webpack
Configure Webpack 5 to handle ES modules correctly.webpack.config.js
TypeScript with Webpack
tsconfig.json
esbuild
Use esbuild for fast builds with Temelj packages.build.js
Rollup
Rollup configuration for Temelj packages.rollup.config.js
Turborepo (monorepo builds)
Temelj itself uses Turbo for its monorepo. Use this configuration as a reference.turbo.json
Using tsdown (Temelj's build tool)
Using tsdown (Temelj's build tool)
Temelj packages use tsdown for builds:tsdown automatically generates optimized
package.json
.mjs and .d.mts files from TypeScript source with zero configuration.Bundle size optimization
Temelj packages are already optimized, but you can further reduce bundle size.Tree shaking
All Temelj packages support tree shaking. Import only what you need:Optimized imports
Code splitting
Split Temelj utilities across chunks for better caching:1
Identify shared utilities
Determine which Temelj packages are used across multiple routes or components.
2
Create dedicated chunks
Configure your bundler to separate frequently-used utilities:
Vite example
3
Measure impact
Use bundle analysis tools to verify size improvements:
Dependency analysis
Check what Temelj packages bring in:Bundle analysis
Most Temelj packages have zero dependencies. Notable exceptions:
@temelj/value: usesdeepmergeandreact-fast-compare@temelj/request: usestough-cookie@temelj/id: usesid128
Production optimization
Optimize for production deployments.Environment-specific builds
vite.config.ts
Compression
Enable compression for maximum size reduction:vite.config.ts
Testing bundled output
Verify your bundle works correctly:Bundle test
Common bundling issues
Module resolution errors
1
Check package.json type
Ensure your project uses ES modules:
2
Verify bundler configuration
Add
.mjs to resolved extensions:3
Update TypeScript config
Set proper module resolution:
Dual package hazard
Avoid importing the same package as both ESM and CJS:Avoid mixing formats
Framework-specific guides
Next.js configuration
Next.js configuration
next.config.js
SvelteKit configuration
SvelteKit configuration
vite.config.js
Astro configuration
Astro configuration
astro.config.mjs
Performance benchmarks
Typical bundle sizes for common Temelj usage:Bundle sizes (minified + gzipped)