Repository navigation
Configuring the the /assets directory?
#13822
|
I'd like to serve build assets ( |
Replies: 1 comment
|
Yes—if you are using React Router’s Vite-based Framework Mode, set Vite’s // vite.config.ts
import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
export default defineConfig(({ command }) => ({
base: command === "build" ? "https://cdn.example.com/" : "/",
plugins: [reactRouter()],
}));With the normal The setting changes the generated URLs; it does not upload files. Publish the client output (normally For cross-origin module loading, configure the CDN’s CORS response headers to allow your application origin and serve JavaScript/CSS with the correct content types. Keep React Router’s This applies to generated build assets. A hard-coded string such as References: Vite |
Yes—if you are using React Router’s Vite-based Framework Mode, set Vite’s
baseto the CDN’s public URL. For example, merge this into your existing Vite configuration, keeping your other plugins/options:With the normal
assetsdirectory, a generatedassets/entry-<hash>.jsis then referenced ashttps://cdn.example.com/assets/entry-<hash>.js. Use the trailing slash. Do not add/assets/tobaseunless your CDN really serves the output under/…