OurBG's avatar
Level 1

Laravel Mix empties file while “watch”-ing

Laravel 5.4.26 NPM 5.4.2 Node 8.1.2

I am running npm run watch and it works perfectly with all my SASS or CSS files. I also have this line of code there:

.scripts(['resources/assets/js/specific/dashboard.js'], 'public/js/specific/all.js')

Every time I run npm run watch dashboard.js is succesfully compiled into all.js.

However every time I make a change in dashboard.js the all.js empties never to fill it up again. If I Ctrl+c the process and run npm run watch again it compiles it successfully again.

If I have more than one js to combine only the one I change gets dropped from the code of the finished all.js.

This is bad because every time I make a change in the js (that I'm currently developing) I need to go back and restart the process and wait for it.

0 likes
5 replies
ejdelmonico's avatar

@ourbg Please post your entire webpack.mix.config. Also, a tip for when things get buggy with Laravel Mix...I usually remove my node_modules and lock file and run npm install again. ( out of 10 times it corrects strange issues because of a problem with a package dependency.

OurBG's avatar
Level 1
let mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/assets/js/app.js', 'public/js')
    .combine([
        'resources/assets/js/specific/articles.js',
        'resources/assets/js/specific/countries.js',
        ], 'public/js/specific/all.js')
    .sass('resources/assets/sass/app.sass', 'public/css');

mix.options({
    processCssUrls: false
});

Doesn't matter if I use combine or scripts or whatever it always empties the compiled file after I change the one in resources dir.

ejdelmonico's avatar

I am not sure what the exact issue is. It is normal for Webpack to re-compile files while running watch. However, I am not sure if combine will run again when a change is detected. That may be the issue you are facing.

OurBG's avatar
Level 1

Maybe yes. It's the same with "scripts" or just "js" instead of combine. But I'm just going to put every js resource into a different file and it's working fine.

ejdelmonico's avatar

I am thinking that you could try to combine first to the resources directory and then run a second js() on that file and maybe watch will pick it up.

.js('resources/assets/js/specific/all.js', 'public/js/specific/all.js')

Please or to participate in this conversation.