Files
sweet/packages/plugin-vite
fry69 6fbe0ddcc4 fix(vite): basePath handling for static assets (#3394)
closes #3391 

---
Generated PR message:

Fix base path handling for assets in plugin-vite

Fixes issue where Fresh apps mounted at non-root paths (e.g., /ui) in
frameworks like Hono would fail to load assets correctly.

  Problem

When mounting a Fresh app with app.mount('/ui', UI.fetch), the HTML
would load but all assets (CSS, JS, images) would return 404 because
asset paths
were hardcoded to start with /assets/ instead of respecting the Vite
base configuration.

  Solution

- Modified packages/plugin-vite/src/plugins/server_entry.ts to read
Vite's base config and apply it to asset paths
- Added getAssetPath() helper function to construct proper asset URLs
with base path
  - Updated both CSS and asset file registration to use the base path

  Testing

Added comprehensive test case "vite build - base path asset handling"
that:
  - Builds demo with custom base path /my-app/
  - Verifies generated server.js contains correctly prefixed asset paths
  - Follows existing test patterns and utilities

  Usage

  Users can now properly mount Fresh apps by configuring both:
```ts
  // vite.config.ts
  export default defineConfig({
    base: "/ui/",
    plugins: [fresh()],
  });

  // main.ts  
  const app = new App({ basePath: "/ui" });

  // hono-app.ts
  app.mount('/ui', UI.fetch); // Assets now work correctly
```

  Backward compatible - no changes needed for apps mounted at root path.
2025-09-11 16:07:15 +02:00
..
2025-09-09 18:52:36 +02:00
2025-09-02 17:41:17 +02:00

Fresh vite plugin

Vite plugin for Fresh.

Usage

  1. Run deno install jsr:@fresh/plugin-vite npm:vite
  2. Ensure that your deno.json has the fresh import mapping:
{
  "imports": {
    "fresh": "jsr:@fresh/core"
  }
}
  1. Update your vite.config.ts file:
  import { defineConfig } from "vite";
+ import { fresh } from "@fresh/plugin-vite";
  
  export default defineConfig({
    plugins: [
+     fresh(),
    ],
  });
  1. Update your deno tasks respectively:
  • Dev: vite
  • Build: vite build

More information on the Fresh documentation .