audunru
839
4
Mix

Run php artisan command before mix build

Posted 1 year ago by audunru

I have a couple of php artisan commands that I'd like to run before my javascript is compiled. So I learned about then(), but that happens after the build. Any suggestions?

Here's my webpack.mix.js

const mix = require('laravel-mix');
const { exec } = require('child_process');

mix
   // Kind of like this, but exactly the opposite...
    .then(() => {
        exec('php artisan routes:javascript');
        exec('php artisan lang:js --no-lib resources/assets/js/translations.js');
    })
    .sass('resources/assets/sass/app.scss', 'public/css')
    .react('resources/assets/js/app.js', 'public/js')
    .browserSync({
        proxy: 'localhost:8000',
    });

if (mix.inProduction()) {
    mix.version();
}

Please sign in or create an account to participate in this conversation.