What url are you visiting when you try to develop the site? http://127.0.0.1:8080 ?
Aug 11, 2022
13
Level 4
Vite and css url() path
Hello,
what's a correct file path for css background-image using vite?
Here is my code:
.webp & {
background-image: url(/images/webp/hero-bg.webp);
}
And I get 404 error in browser in dev mode:
GET http://localhost:5173/images/webp/hero-bg.webp 404 (Not Found)
But it's all good in production build.
I tried to use relative path - it's went good in dev mode, but it's not found in production build.
My vite.config.js:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
const path = require('path');
export default defineConfig({
server: {
host: '127.0.0.1',
},
resolve: {
alias: {
'~bootstrap': path.resolve(__dirname, 'node_modules/bootstrap'),
}
},
plugins: [
laravel({
input: [
'resources/sass/app.scss',
'resources/js/app.js',
'resources/js/navigation-drawer.js',
'resources/js/modernizr-custom.js',
],
refresh: true,
}),
],
});
.env:
...
APP_URL=http://127.0.0.1:8080
...
public/hot:
http://127.0.0.1:5173
I use php artisan serve --port 8080 for a local dev server
Please or to participate in this conversation.