【问题标题】:Integrate Grunt with Visual Studio publish option将 Grunt 与 Visual Studio 发布选项集成
【发布时间】:2016-10-12 10:06:23
【问题描述】:

当我为开发/测试/生产发布我的 Web 应用程序时,我想执行 grunt 任务。

现在,当我构建解决方案时,当时我已配置为执行 grunt 任务。但是,当我发布我的 Web 应用程序时,即使 Visual Studio 在发布之前构建解决方案,它也不会执行。

知道我该怎么做吗?

【问题讨论】:

    标签: javascript gruntjs publishing webdeploy task-runner-explorer


    【解决方案1】:

    您尚未指定 Visual Studio 版本。我发现这适用于 VS 2015 和 .Net 核心

    我已使用 Grunt 和 Project.JSON 文件来完成此操作。

    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" ]
    
      }
    

    【讨论】:

      猜你喜欢
      • 2013-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-11
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多