ijpatricio / mingle

Use JS components with Vue or React in a Laravel Livewire and/or Filament application
MIT License
205 stars 6 forks source link

Include JS files for bundling automatically - avoid manually adding to `vite.config.js` #9

Open Felipe-DevT00ls opened 2 months ago

Felipe-DevT00ls commented 2 months ago

After generating the Vite build, I receive the following error: image

This is the command to generate the Vite build: image

This is my Vite structure: image

This is my resources/js folder structure: image

Felipe-DevT00ls commented 2 months ago

To solve this problem by modifying the vite.config.js to the following form:

image

The paths "resources/js/front-end" and "resources/js/front-end//index.js" are specific to my project, in common cases, you can just use "resources/js/" and "resources/js//index.js"

I would like this configuration to be a standard feature of the mingleJs project, as it allows for dynamic rather than static builds, as seen in the mingle-demo example.

Aqui está o vite.config.js

import { defineConfig } from "vite";
import laravel from "laravel-vite-plugin";
import vue from "@vitejs/plugin-vue";
import { sync } from "glob";
import path from "path";

let js = sync("resources/js/front-end/**/index.js").map((file) => ({
    input: path.relative(
        "resources/js/front-end",
        file.slice(0, file.length - path.extname(file).length)
    ),
    file: file,
}));

let input = js.map(({ file }) => file);

export default defineConfig({
    resolve: {
        alias: {
            "@mingle": path.resolve(
                __dirname,
                "vendor/ijpatricio/mingle/resources/js"
            ),
        },
    },
    plugins: [
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
        laravel({
            input: ["resources/css/app.css", "resources/js/app.js", ...input],
            refresh: true,
        }),
    ],
    server: {
        cors: true,
    },
});
ijpatricio commented 2 months ago

Hello @Felipe-DevT00ls

Sorry for a long delay, I was buried in work, and this wasn't a bug, so I left it for later.

This is a great addition!! How I see it, it shouldn't be a default, because not everyone is using index.js as the name for the js.

There could be a ChatApp.js, for example.

The concept is great, though, so I will think of a way of including it, or adapting it to fit all cases.

Thank you so much for the inputs!!