Rollup, Rolldown and tsdown
Use tyfigo/rollup and tyfigo/rolldown.
Rollup
Rollup doesn't know whether it builds for the browser or a server, so the plugin defaults to the
browser target. Set target: 'server' for a server bundle:
import tyfigo from 'tyfigo/rollup';
export default {
input: 'src/server.js',
output: { file: 'dist/server.mjs', format: 'es' },
external: ['tyfigo/runtime'],
plugins: [tyfigo({ target: 'server' })],
};Rolldown
Rolldown's platform picks the target: node is a server build, browser (or neutral) a browser build.
import tyfigo from 'tyfigo/rolldown';
export default {
input: 'src/server.ts',
platform: 'node',
output: { file: 'dist/server.mjs', format: 'es' },
plugins: [tyfigo()],
};tsdown
tsdown takes Rolldown plugins, and builds for node by default:
import { defineConfig } from 'tsdown';
import tyfigo from 'tyfigo/rolldown';
export default defineConfig({
entry: ['src/main.ts'],
plugins: [tyfigo()],
});None of these have a mode. A browser build uses NODE_ENV at build time, and a server build inlines every environment's layer
files and picks them by NODE_ENV when it runs (Server bundles), unless you pass
environment. A server build reads .env files and environment variables when it runs, through tyfigo/runtime; keep that
import external when the bundle runs next to an installed tyfigo.