Next.js
Wrap your Next.js config with withTyfigo for webpack, Turbopack and the type check.
import { withTyfigo } from 'tyfigo/next';
export default withTyfigo({});withTyfigo(nextConfig, options?) adds:
- Loader rules for webpack and Turbopack. Client components and Edge code get the browser build:
base and environment files inlined, placeholders fail the build. Node.js server code gets the base, local and every environment's files
inlined, and picks them by
NODE_ENVwhen the server starts (Server bundles), with.envfiles and environment variables read then too. - A type check that can read config imports.
next buildtype-checks without--runExternalCode, sowithTyfigoturns that check off (typescript.ignoreBuildErrors) and runstsc --noEmit --runExternalCodeafter the production compile. Pass{ typeCheck: false }to skip it, for example when CI runs tsc separately.
Options: environment (defaults to NODE_ENV; setting it fixes the server's environment), runtime and typeCheck.
Server and client config
From the next example:
site:
name: tyfigo + Next.js
supportEmail: support@localhost
cms:
url: ${CMS_URL}
token: ${CMS_TOKEN}
revalidateSeconds: 60theme: light
banner: Development buildimport { Banner } from './banner.tsx';
import config from '../config/app.config.yaml';
export default function Page() {
const cms = new URL(config.cms.url);
return (
<main>
<Banner />
<p>{cms.host}</p>
</main>
);
}'use client';
import config from '../config/public.config.yaml';
export function Banner() {
return <p data-theme={config.theme}>{config.banner}</p>;
}app.config.yaml has placeholders, so importing it from a client component fails the build. public.config.yaml has none.
Type checking
next typegen writes the route types tsc needs, so run it before tsc:
{
"scripts": {
"build": "next build",
"typecheck": "next typegen && tsc --noEmit --runExternalCode"
}
}With Turbopack, next build warns that dynamic filesystem access traces the whole project. That comes from the .env
lookup in tyfigo's runtime. The build still succeeds.