question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating Multiple Bundles

See original GitHub issue

Is it possible to create multiple bundles same time? So my plan is separating frontend assets from backend assets.

Example

Frontend

laravel([
            'resources/css/frontend/app.css', 
            'resources/js/frontend /app.js',
        ]),

Backend

laravel([
            'resources/css/backend/app.css', 
            'resources/js/backend /app.js',
        ]),

Thank you!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ercanertancommented, Nov 14, 2022

@garbinmarcelo Unfortunately I couldn’t find any solution. I am keeping webpack with mix.

0reactions
garbinmarcelocommented, Nov 17, 2022

may be with this?

https://laravel-vite.dev/guide/extra-topics/multiple-configurations.html

Hello, this is not the official package and everything indicates that it will be discontinued.

I managed to do it the following way, I created 2 files:

vite.config.js

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            hotFile: 'public/build/web.hot',
            buildDirectory: 'build/web',
            input: [
                'resources/css/app.css',
                'resources/js/app.js'
            ],
            refresh: [
                'app/Modules/**',
                'resources/views/**',
                'public/**',
                'lang/**'
            ],
        }),
    ],
    server: {
        hmr: {
            host: 'localhost',
        },
        watch: {
            usePolling: true
        }
    }
});

vite.painel.config.js (in my case this is the admin)

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            hotFile: 'build/painel.hot',
            buildDirectory: 'build/painel',
            input: [
                'resources/painel/app.scss',
                'resources/painel/app.js'
            ],
            refresh: [
                'app/Modules/**',
                'resources/views/**',
                'public/**',
                'lang/**'
            ],
        }),
    ],
    resolve: {
        alias: {
            '@': '/resources/painel/js',
        },
    },
    server: {
        hmr: {
            host: 'localhost',
        },
        watch: {
            usePolling: true
        }
    }
});

package.json

"scripts": {
        "dev": "vite",
        "dev.painel": "vite --config vite.painel.config.js",
        "dev.all": "npm run dev && npm run dev.painel",
        "build": "vite build",
        "build.painel": "vite build --config vite.painel.config.js",
        "build.all": "npm run build && npm run build.painel"
    },

In my admin blade layout I use the following: @vite(['resources/painel/app.scss', 'resources/painel/app.js'])

To set the correct panel build folder I define it in the provider boot, for example:

public function boot()
    {
        ...
        Vite::useBuildDirectory('build/painel');
         ...
    }

Posts that helped me reach this result: https://github.com/innocenzi/laravel-vite/discussions/324#discussioncomment-4135369 https://github.com/laravel/docs/pull/8146#issuecomment-1315986922

The “useBuildDirectory” can be invoked in several ways as explained in the post, linked above.

Hope I helped in some way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple bundles with webpack - Stack Overflow
js file to the src directory, we need to make a change to the file webpack.config.js , which I don't like. Is there...
Read more >
Webpack: Creating multiple bundles using entry points
A guide on creating optimizing a mult-page site using Webpack with multiple entry points.
Read more >
Code Splitting - webpack
This feature allows you to split your code into various bundles which can then be loaded on demand or in parallel. It can...
Read more >
Building Applications with Multiple Bundles - Apple Developer
Explains how Cocoa applications can dynamically load code during execution.
Read more >
multiple-bundles-webpack-plugin - npm
Create multiple bundles from independent js/scss components. ... This plugin prevents Webpack 4 from creating an separate output file from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found