Rober
Rober

Reputation: 6098

Grunt prettify or not uglify in development environment

I´m using Grunt Uglify in my AngularJS web application to uglify my javascript and css files.

I have a development, test and production environments. I would like to uglify only when deploying to test and production, but in development I would like to keep my code without uglify to make the debugging tasks easier.

So far, I´m doing manually. I mean, I have an index.html with all beauty code, and the moment I´m going to deploy a release, I uglify the code and deploy.

Upvotes: 1

Views: 335

Answers (1)

Louis Barranqueiro
Louis Barranqueiro

Reputation: 10228

Use grunt.registerTask function to create a task to run tasks on development and an other task to run tasks before deploy.

Here is an example :

In development env, I'm running the buildDev task to compile scss files and link them to a template files

module.exports = function(grunt) {
    grunt.registerTask('buildDev', [
        'sass:website',
        'asset-linker:websiteCSS',
        'asset-linker:websiteJS',
    ]);
};

Before deploy my application in prod, I run buildProd task to run additional tasks like concat, cssmin, uglify :

module.exports = function(grunt) {
    grunt.registerTask('buildProd', [
        'clean:websiteStatic',
        'sass:website',
        'concat:websiteCSS',
        'concat:websiteJS',
        'cssmin:website',
        'uglify:website',
        'asset-linker:prodWebsiteCSS',
        'asset-linker:prodWebsiteJS',
    ]);
};

Then, create two register task, one to run task in your dev env, and one before deploying your app.

I recommend you to read Grunt Documentation - register task for more details

Upvotes: 1

Related Questions