markotitel's avatar

Laravel mix for dev and production

Hi,

My dev experience is low, just started with Laracasts as complete beginner in coding. But I have some sysadmin exp. I have a Gitlab Ci/CD pipeline and building assets before deployment.

I want to tell Laravel-Mix to behave differently for local dev and for production.

I want SourceMaps to compile differently depending on ENV.

How can I achieve this?

0 likes
4 replies
markotitel's avatar

Yes but how should I do it in webpack.mix.js?

Should I use if ?

How should actually write this?

markotitel's avatar

Yes, thank you.

Just refreshed to post Laravel Documentation solution, which I could not notice today. So my webpack.mix looks like

const 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/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css');

if(!mix.inProduction()) {
   mix.sourceMaps();
   mix.webpackConfig({ devtool: 'inline-source-map'})
}
1 like

Please or to participate in this conversation.