bump.
Sep 15, 2024
6
Level 13
make vite generate relative URLs
Howdy artisans,
how can I make vite generate relative URLs?
I already tried this:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css'],
refresh: true,
}),
],
base: ''
});
But all I get are still absolute URLs when including the CSS file by using:
@vite('resources/css/app.css')
Any idea what I do wrong here?
Using
ASSET_URL="/"
Had the effect of generating incorrect URLs like:
//build/assets/app-b30c7c50.css
setting it to
ASSET_URL=""
or
ASSET_URL=null
had no effect at all (meaning still absolute URL was generated).
Level 25
<link rel="preload" as="style" href="/build/assets/app-CeQoy5CN.css">
All I did was create a brand new laravel app:
laravel new urltest
Edit .env to have the ASSET_URL config
ASSET_URL="/"
Edit the app.css so it wasn't empty:
body {
background: gray;
}
Add @vite directive to welcome.blade.php in place of the style tags:
@vite(['resources/css/app.css', 'resources/js/app.js'])
Install js dependencies and compile
npm install
npm run build
Open up urltest.test in the browser.
Inspection showed as above, and the js script tags were the same.
1 like
Please or to participate in this conversation.