javascriptgruntjspublishingwebdeploytask-runner-explorer

Integrate Grunt with Visual Studio publish option


I want to execute grunt task when I publish my web application for either dev/test/production.

Right now, when I build my solution, at that time I've configured to execute grunt task.But,when I publish my web app it doesn't execute even if visual studio builds solution before publishing.

Any idea how can I do this?


Solution

  • You have not specified the Visual Studio version. I found this works with the VS 2015 and .Net core

    I have used Grunt & Project.JSON files for accomplishing this.

    Grunt.JS

    module.exports = function (grunt) {
        grunt.loadNpmTasks('grunt-contrib-uglify');
        grunt.loadNpmTasks('grunt-contrib-watch');
        grunt.loadNpmTasks('grunt-contrib-cssmin');
        grunt.loadNpmTasks('grunt-contrib-clean');
    
    
        grunt.initConfig({
    
            uglify: {
                options: {
                    mangle: false,
                    beautify: true
                },
                my_target: {
                    files: {
                        'wwwroot/app/app.js':
                            [
                                 'wwwroot/*.js',
                                 'wwwroot/services/*.js',
                                 'wwwroot/view/**/*.js',
                                 'wwwroot/common/*.js'
                            ]
                    }
                }
            },        
    
            cssmin: {
                options: {
                    shorthandCompacting: false,
                    roundingPrecision: -1
                },
                target: {
                    files: {
                        'wwwroot/app/app.css':
                        [
                            'wwwroot/*.css',
                            'wwwroot/view/**/*.css'
                        ]
                    }
                }
            },
    
            watch: {
                scripts: {
                    files: [
                                'wwwroot/services/*.js',
                                'wwwroot/view/**/*.js',
                                'wwwroot/*.js'
                            ],
                    tasks: ['uglify']
                },
                css: {
                    files: [
                            'wwwroot/*.css',
                            'wwwroot/view/**/*.css'
                            ],
                    tasks: ['cssmin']
                }
            },
            clean: {
                prod: {
                   src: ['wwwroot/pdf/*']
                }
            }
    
        });
    
    
        grunt.registerTask('build', ['uglify', 'cssmin', 'clean']);
    };
    

    Project.Json

    "scripts": {
        "prepublish": [ "grunt build" ]
    
      }