exaco / laravel-octane-dockerfile

Production-ready Dockerfile for Laravel Octane (FrankenPHP, Swoole, RoadRunner) powered web services and microservices. Done right.
MIT License
540 stars 82 forks source link

Node assets build should occur after composer install #68

Open Velka-DEV opened 3 months ago

Velka-DEV commented 3 months ago

The docker build will fail if any javascript file import a resource from composer vendor folder (e.g Alpine / Livewire)

import { Livewire, Alpine } from '../../vendor/livewire/livewire/dist/livewire.esm';

This import is from the Livewire documentation: https://livewire.laravel.com/docs/alpine#manually-bundling-alpine-in-your-javascript-build

smortexa commented 3 months ago

PHP dependencies (vendor directory) are not available during the build of front-end assets in these Dockerfiles. You can do this:

// composer.json
"post-update-cmd": [
     ...
      "@php -r \"copy('vendor/livewire/livewire/dist/livewire.esm', 'resources/js/lib/livewire/livewire.esm');\""
    ],

// app.js
import { Livewire, Alpine } from './lib/livewire/livewire.esm';

Then, run composer update and rebuild the image.

Velka-DEV commented 3 months ago

We need to expose vendor directory, this is not actually reliable to copy all dependencies.

The ESM module make relative imports like "../alpine/packages/alpinejs/dist/module.cjs.js", we can't copy every single file manually

Velka-DEV commented 2 months ago

Maybe this is a good occasion to work on it along with alpine & bun support as it's on the to-do list and would be a rewrite