Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Elixir: How to execute a task only in production mode?

I am using a bunch of "console.log" calls for debugging my JS application. However, I'd like to remove these automatically when sending the code to production.

Using a traditional gulpfile, I would use the "gulp-strip-debug" plugin that will be only triggered when I run the "production" main task.

When using Laravel Elixir, though, it's a little bit different. I use the "--production" flag to minimize my assets, but I'd like to execute the strip-debug task afterwards. I could not find how to do that in the Laravel 5.1 documentation.

like image 772
kant312 Avatar asked Aug 18 '15 09:08

kant312


1 Answers

After checking the elixir.config object, it seems that the --production flag sets the elixir.config.production variable to true.

It is therefore possible to wrap the execution of a specific task in an if(elixir.config.production) statement, allowing you to trigger them when the environment is "production" or if you manually specified it by using the --production flag from the command line.

like image 83
kant312 Avatar answered Nov 10 '22 12:11

kant312