OK so the second command I was able to remove because the author has created something specific for webpack... https://github.com/rmariuzzo/laravel-localization-loader
Dec 26, 2017
4
Level 4
Run php artisan command before mix build
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();
}
Level 4
And the other command I was able to use WebpackShellPlugin. Here's what I ended up with:
const mix = require('laravel-mix');
const WebpackShellPlugin = require('webpack-shell-plugin');
mix.webpackConfig({
plugins: [
new WebpackShellPlugin({ onBuildStart: ['php artisan routes:javascript'], onBuildEnd: [] }),
],
module: {
rules: [
{
// Matches all PHP or JSON files in `resources/lang` directory.
test: /resources(\|\/)lang.+\.(php|json)$/,
loader: 'laravel-localization-loader',
},
],
},
});
mix.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 or to participate in this conversation.