Getting Started
  • Introduction
  • Installation
  • About
Core Concepts
  • Routing System
  • Page Functions
  • Data Fetching
  • Server Components
  • Client Components
  • Server Functions
  • 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" />;
}
With Server Components instead of Client Components works exactly the same.

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 this place:

  • dinou/asset-extensions.js

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

On This Page

OverviewUsageTypeScript DeclarationCustom Extensions