Podgy's avatar
Level 1

Laravel Mix Watch Compiling/Emitting All Files

Hi all,

I've done some digging but I can't seem to find a solution to my issue. I would essentially like webpack/mix to only compile the file that has been edited instead of what I think it's doing and compiling everything. I have a JavaScript file for each laravel view which is using Vue, so a Vue standalone app for each page. This means that there are a fair few files for mix to compile and copy over into the relevant folders:

const mix = require('laravel-mix');
const path = require('path');

/*
 |--------------------------------------------------------------------------
 | 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.alias({
    '@': path.join(__dirname, 'resources/js'),
    '~': path.resolve(__dirname, 'resources/sass/'),
})
    .options({
        terser: {
            extractComments: false,
            terserOptions: {
                compress: {
                    defaults: false,
                    drop_console: true
                }
            }
        }
    })

mix.version();

mix.setPublicPath('public')
    .js('resources/js/app.js', 'public/js')
    .js('resources/js/admin/sample/sample-edit.js', 'public/js/admin/sample')
    .js('resources/js/admin/sample/test-edit.js', 'public/js/admin/sample')
    .js('resources/js/client/sample/fake-edit.js', 'public/js/client/sample')
    .sass('resources/sass/client.scss', 'public/css').options({processCssUrls: false})
    .sass('resources/sass/admin.scss', 'public/css').options({processCssUrls: false})
    .sourceMaps(false, 'source-map')
    .vue()

Once I run npm run watch and edit sample-edit.js for example, mix will end up presenting me with:

/js/sample-edit.js │ 3.25 MiB │                                                                                                                                           /js/sample-edit.js.map │ 3.76 MiB │              
/js/test-edit.js │ 3.25 MiB │                                                                                                                                          
/js/test-edit.js.map │ 3.76 MiB │              
/js/fake-edit.js │ 3.25 MiB │                                                                                                                                          
/js/fake-edit.js.map │ 3.76 MiB │                                                                                                                                                  css/admin.css │ 59.3 KiB │                                                                                                                                                                   css/admin.css.map │ 84.9 KiB │                                                                                                                                                                      css/client.css │ 55.8 KiB │                                                                                                                                                                css/client.css.map │ 78.9 KiB 

It appears there are files in the compiled list which I didn't edit. I would only expect to find sample-edit.js in there and its map file. I currently have over 50 singular JS files in this structure and having watch recompile them all takes a while. It seems to hang the longest on the 'emit' stage at 95%.

Any help or suggestions greatly welcomed and appreciated.

0 likes
0 replies

Please or to participate in this conversation.