Getting Started
  • Introduction
  • Installation
  • About
Core Concepts
  • Routing System
  • Page Functions
  • Data Fetching
  • Server Components
  • Client Components
  • Advanced
Features
  • Dynamic & Query Parameters
  • Navigation
  • Styles & CSS
  • Assets
  • Favicons
Configuration
  • Environment Variables
  • Import Aliases
  • Ejecting
  • Deployment
dinou logodinou
docs
npmGitHub

Assets or Media Files

Learn how to use media files like images, video, and sound in dinou.

Overview

dinou supports the use of media files in your components. Supported file extensions are:.png, .jpeg, .jpg, .gif, .svg, .webp, .avif, .ico, .mp4, .webm, .ogg, .mov, .avi, .mkv, .mp3, .wav, .flac, .m4a, .aac, .mjpeg, .mjpg.

Usage

Just import the asset as a default import and use it in your component:

// src/component.tsx
"use client";

import image from "./image.png";

export default function Component() {
  return <img src={image} alt="image" />;
}
Important: Only assets imported under a "use client" directive will be detected by dinou and generated in the public folder.

With Server Components

If you're using server components, you need to create a separate client file (e.g. assets.ts) to trigger dinou's detection:

Client Asset File

// src/assets.ts
"use client";

import "./image.png";

Server Component

// src/component.tsx
import image from "./image.png";

export default async function Component() {
  return <img src={image} alt="image" />;
}

TypeScript Declaration

You should declare each supported file extension in a declaration file (e.g. src/assets.d.ts):

// src/assets.d.ts
declare module "*.jpeg" {
  const value: string;
  export default value;
}

declare module "*.jpg" {
  const value: string;
  export default value;
}

declare module "*.png" {
  const value: string;
  export default value;
}

// continue with the rest...

Custom Extensions

If you need to support a new file extension, you can eject and customize dinou. Add the extension in these three places:

  • rollup.config.js
  • dinou/server.js
  • dinou/render-html.js

Just search for the existing file extensions and append your own.

On This Page

OverviewUsageWith Server ComponentsTypeScript DeclarationCustom Extensions