calin.ionut's avatar

use laravel-mix to create more then one js mix

I have the following scenario:

I have 2 views product.blade.php and checkout.blade.php (a product page and a checkout page)

In the package.json I will install all the vue modules and what is needed for all the pages ( product and checkout)

I want to have 2 different app.js with different logic and vue modules loaded: one for product and one for checkout. I want to be able to run dev or compile for production separately and import them in the blade files:

in product.blade.php

<script src="{{ mix('/js/product.js') }}"></script>

and in the checkout.blade.php

<script src="{{ mix('/js/checkout.js') }}"></script>

Every page has different modules loaded and different logic. I don't one big app.js to load all the logic and modules for all the pages.

It is possible to use laravel-mix to work like I want?

0 likes
9 replies
calin.ionut's avatar

@michaloravec it does the trick :)

How can I work with only one file at a time, I mean if I run

npm run watch

it will compile both of them. Probably the same if run

npm run production

That means if I work and make changes only in product.js and run watch or production it make changes in checkout.js too.

Is there a way to run watch or run production for a single file ?

calin.ionut's avatar

@michaloravec I didn't solve the " run production for a single file" problem.

I was busy this week....i will give it a read the article that @sidneygijzen posted and see if it's work.

calin.ionut's avatar

Any updates in the new version of mix that can run scripts on different mix js ?

If having :

mix.js('resources/js/product.js', 'public/js/product.js');

mix.js('resources/js/checkout.js', 'public/js/checkout.js');

to run them individual:

ex:

npm run watch product_mix

or

npm run watch checkout_mix

???

Please or to participate in this conversation.