Skip to content
Discussion options

You must be logged in to vote

Yes—if you are using React Router’s Vite-based Framework Mode, set Vite’s base to the CDN’s public URL. For example, merge this into your existing Vite configuration, keeping your other plugins/options:

// 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 assets directory, a generated assets/entry-<hash>.js is then referenced as https://cdn.example.com/assets/entry-<hash>.js. Use the trailing slash. Do not add /assets/ to base unless your CDN really serves the output under /…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by davidbielik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants