2

I use Laravel Mix - it's a flexible way to use webpack easily.

When running watch it will recompile dev mode builds whenever the files change. However, in order to use these there's an external build step - e.g. one project needs to call drush cc css-js .

Is there a way to do this from the webpack.mix.js file or other?

Sort of like:

mix()
 .js('src/app.js', 'dist/')
 .vue()
 .shell('drush cc css-js') // ««« something like this?
;

OR perhaps it has to go in the package.json's .scripts bit?

artfulrobot
  • 20,637
  • 11
  • 55
  • 81

1 Answers1

3

You might want to use Event Hooks to this end.

In Laravel Mix v6, you can use Event Hooks (v6) like this:

const { exec } = require('child_process');

mix.js('src/app.js', 'dist/')
   .vue()
   .after(() => {
        exec('drush cc css-js');
    });

If you want to execute something before compiling the resources, use mix.before() instead of mix.after().

Edit: As OP has pointed out below, in Laravel Mix v5, you had to use an Event Hook (v5) mix.then() to run arbitrary code after executing the mix. There was no Event Hook to run code before executing the mix.

lej
  • 46
  • 4
  • Excellent! thanks so much (and welcome to StackOverflow!) I found [docs for child_process.exec](https://nodejs.org/docs/latest-v14.x/api/child_process.html#child_process_child_process_exec_command_options_callback) and note that in Mix v5 you have to use `then()` in place of `after()`. – artfulrobot Dec 14 '20 at 11:57