kool-dev / kool

From local development to the cloud: web apps development with containers made easy.
https://kool.dev
MIT License
665 stars 45 forks source link

Laravel preset with vite #429

Closed danielsuguimoto closed 1 year ago

danielsuguimoto commented 2 years ago

Describe the bug

Laravel latest versions are coming with vitejs that starts a server to handle frontend files. So kool run yarn/npm run dev starts that server instead of only bundling the frontend files, making the laravel setup script to start a daemon.

We could change laravel preset to add a node server on docker-compose.yml for this. The problem would be older laravel versions.

To Reproduce

Creates a laravel project from scratch and run kool run setup. It starts a vite daemon.

ajirandhi commented 2 years ago

I had same problem and i got workaround to solve it, first in kool.yml in the npm and npx command add flag -p [hostPort]:[containerPort] , for example

npm: kool docker -p 5173:5173 kooldev/node:16 npm
npx: kool docker -p 5173:5173 kooldev/node:16 npx

and then in vite.config.js add this following code

server: {
    host: true
},

this is example in my file

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
    server: {
        host: true
    },
    plugins: [
        laravel({
            input: 'resources/js/app.js',
            refresh: true,
        }),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
    ],
});

after that you just run the command

kool run npm run dev

hope this help

danielsuguimoto commented 2 years ago

@ajirandhi Hey! Thanks! I use a similar workaround! We're working on a PR to fix that

fabriciojs commented 1 year ago

This has been released, assuming it was fixed @danielsuguimoto - please reopen if I am mistaken.