Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bhojkamal's avatar

how to build separate js, css bundle for frontend and backend using vite in laravel?

Hello,

How to build frontend and backend separate jss css bundle using vite in laravel application? In frontend I'm using tailwind css and tailwind elements and I'm using bootstrap 5 and admin lte for admin panel - backend. I hope someone already done this. what configuration in vite configuration will give such build output.

Thanks in advance.

0 likes
7 replies
MohamedTammam's avatar

What do you mean by you're using bootstarp on the back-end?

Just use different file for each side

In Laravel Mix

mix.css('resources/your_backend_file.css', '.css')
	.css('resources/your_front_end.css', 'css')
	// ... etc
bhojkamal's avatar

@MohamedTammam question is clear, I want js and css bundle separate for frontend and js and css bundle for backend separate. And I want to use vite because vite is default compiler/mixer now in laravel 9. If I use just one bundle, It will be so big and for frontend pages, the backend js and css is not needed and vice versa.

1 like
MohamedTammam's avatar
Level 51

@bhojkamal In your vite config add your files in Laravel plugin

plugins: [
	laravel([
		 'resources/js/front.js',
		 'resources/js/back.js',
	]),
// ...

The use vite directive for to add your files for each page

Back-end

@vite( 'resources/js/back.js')

Front-end

@vite( 'resources/js/front.js')
2 likes
fuzin's avatar

@MohamedTammam but this makes one build folder with combined code. Is it possible to make completely different bundle for admin panel?

1 like
bhojkamal's avatar

@fuzin

yes for admin panel, import all css and js in admin.js and for frontend import all css and js in frontend.js. It worked. He got best answer already.

Lumethys's avatar

basically, your app is split to 2 part: the normal part and an admin area

do not get confuse between frontend/ backend and application's area

Your admin panel need a backend AND a frontend, your normal app also need a backend AND a frontend

Please or to participate in this conversation.