The user is asking about how to rearrange or manipulate the position of assets in relation to how they're referenced by HTML and code. This is about how Vite outputs files and how they're referenced in the built HTML/JS.
Looking at the vite.config.ts file:
- Entry point is `./src/index.html`
- Output file names:
- `entryFileNames: "js/[name]-[hash].js"`
- `chunkFileNames: "js/[name]-[hash].js"`
- `assetFileNames: "assets/[name]-[hash].[ext]"`
So the user can control:
1. The directory structure of output files
2. The naming patterns (including hashes)
3. How assets are referenced in HTML/JS (Vite handles this automatically via its build system)
The user might want to:
- Change output directory structure
- Remove hashes from filenames
- Change asset file naming patterns
- Control how assets are referenced (base paths, public paths, etc.)
I should explain the Vite configuration options that control this.
Vite Output Configuration (vite.config.ts:22-31)
rollupOptions: {
input: "./src/index.html",
output: {
entryFileNames: "js/[name]-[hash].js", // Main JS files
chunkFileNames: "js/[name]-[hash].js", // Code split chunks
assetFileNames: "assets/[name]-[hash].[ext]", // CSS, images, fonts
},
}
Common Manipulations
Remove hashes (for debugging/CDNs):
entryFileNames: "js/[name].js"
chunkFileNames: "js/[name].js"
assetFileNames: "assets/[name].[ext]"
Change directory structure:
// Flatten everything
entryFileNames: "[name].js"
assetFileNames: "[name].[ext]"
// Organize by type
assetFileNames: "[ext]/[name]-[hash].[ext]"
Custom public path (asset base URL):
base: "/cdn/",
// or environment-specific
base: process.env.CDN_URL || "/"
Manual asset import control:
// In src/index.html or .tsx files
import logo from "./logo.png?url" // Get URL instead of bundling
import styles from "./style.css?inline" // Inline CSS
Important Notes
- Vite automatically updates HTML references during build
- Hashes in filenames enable cache busting (recommended for production)
copyPublicDir: true copies public/ to output root
- Worker fetches assets via paths relative to
dist/ (wrangler.jsonc:22)