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?
grunt. util. _ is deprecated and we highly encourage you to npm install lodash and var _ = require('lodash') to use lodash .
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.
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.
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.
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']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With