This example demonstrates how to deploy a static website to ICP using the asset-canister recipe.
The asset-canister recipe makes it easy to deploy a canister hosting static assets.
The icp.yaml file configures a canister using the asset-canister recipe:
canisters:
- name: frontend
recipe:
type: "@dfinity/asset-canister@<version>"
configuration:
build:
- npm install
- npm run build
dir: disttype: "@dfinity/asset-canister@<version>": Uses the asset-canister recipe for hosting static files. See available versions.build: Specifies the build commands to run before uploading assetsdir: Specifies the directory containing the built assets to upload
package.json: npm package configuration with build scriptssrc/index.html: HTML entry point for the websitesrc/main.ts: TypeScript entry pointsrc/style.css: CSS stylespublic/: Static assets served as-isvite.config.ts: Vite build configuration
- ICP-CLI uses the
asset-canisterrecipe to expand the build and sync steps of the canister. - The build command (
npm run build) uses Vite to compile and bundle assets into thedistdirectory. - The asset canister is deployed.
- The contents of the
distdirectory are synchronized to the asset canister.
- Static websites and landing pages
- Single-page applications (SPAs)
- Frontend applications built with Vite
- Projects that don't require a backend canister
# Start a local network
icp network start -d
# Build and deploy the canister
icp deploy
# Open the deployed frontend in a browser using the canister ID from the output of
# `icp deploy`: http://<frontend_canister_id>.localhost:8000/
# Stop the network
icp network stop