Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternate grunt.js tasks for dev/prod environments

I am trying to set up my grunt.js file so it only runs the min task when running on my production server - when running on my local dev server I don't want to min my code with every change as it is unnecessary.

Any ideas on how grunt.js can differentiate between dev/prod environments?

like image 861
Ben Avatar asked Dec 10 '12 11:12

Ben


People also ask

Is grunt deprecated?

grunt. util. _ is deprecated and we highly encourage you to npm install lodash and var _ = require('lodash') to use lodash .

Is grunt still used?

The Grunt community is still going strong and both tools look like they're going to be around for a while yet. I should mention that another up and coming alternative to task runners like Grunt and Gulp is simply using npm scripts with command-line tools.

What is Gruntfile JS used for?

Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file (known as a Gruntfile). Grunt was created by Ben Alman and is written in Node. js.

What is the other name of the plugins in grunt?

grunt-contrib-concatby Grunt TeamConcatenate files. main-bower-filesby Christopher KnötschkeGet main files from your installed bower packages. jit-gruntby shootarooJIT plugin loader for Grunt. grunt-newerby Tim SchaubRun Grunt tasks with only those source files modified since the last successful run.


1 Answers

Register a production task:

// on the dev server, only concat grunt.registerTask('default', ['concat']);  // on production, concat and minify grunt.registerTask('prod', ['concat', 'min']); 

On your dev server run grunt and on your production run grunt prod.

You can setup finer grain targets per task as well:

grunt.initConfig({   min: {     dev: {       // dev server minify config     },     prod: {       // production server minify config     }   } }); grunt.registerTask('default', ['min:dev']); grunt.registerTask('prod', ['min:prod']); 
like image 88
Kyle Robinson Young Avatar answered Sep 19 '22 11:09

Kyle Robinson Young