【问题标题】:UglifyJS in Visual Studio 2015 only in release modeVisual Studio 2015 中的 UglifyJS 仅在发布模式下
【发布时间】:2015-04-21 09:25:26
【问题描述】:

我已在 Visual Studio 2015 中配置 GruntJS 以使用 UglifyJS 缩小我的 JavaScript 文件。工作正常。

但是,我希望只有在 Visual Studio 处于发布模式时才会发生这种情况。在调试模式下,我想调试我的 JavaScript 文件,而缩小的 JavaScript 很难(不可能)调试。

【问题讨论】:

    标签: gruntjs uglifyjs grunt-contrib-watch grunt-contrib-uglify visual-studio-2015


    【解决方案1】:

    我使用 ASP.Net 5 任务运行器解决了这个问题。

    我的解决方案具有以下文件夹层次结构。

    Solution
    ->wwwroot
    ->Scripts
      ->app.js
      ->Controllers
        ->controller1.js
        ->controller2.js
    

    1.) 文件监视程序监视 Scripts 目录和所有子文件夹。

    2.) 当检测到文件更改时,所有 *.js 文件都会从脚本文件夹复制到我的脚本文件夹中的 wwwroot 目录。

    3.) 然后在 wwwroot 目录中的脚本文件夹上运行 uglify 任务,这会将其缩小为单个 app.js 文件,供 html 应用程序引用。

    uglify 任务将 sourceMap 选项转为 turn,这允许 javascript 调试器在调试模式下引用脚本,但在非调试模式下运行时使用缩小的脚本。

    module.exports = function (grunt) {
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-copy');
    
    grunt.initConfig({
        copy: {
            main: {
                files: [
                    {
                        expand: true,
                        src: ['Scripts/app.js', 'Scripts/Controllers/**'],
                        dest: 'wwwroot'
                    }
                ]
            }
        },
        uglify: {
            my_target: {
                files: { 'wwwroot/app.js': ['wwwroot/Scripts/app.js', 'wwwroot/Scripts/**/*.js'] },
                options : {sourceMap : true}
            }
        },
        watch: {
            scripts: {
                files: ['Scripts/app.js','Scripts/**/*.js'],
                tasks: ['copy:main', 'uglify']
            }
        }
    });
    
    grunt.registerTask('default', ['copy:main', 'uglify', 'watch:scripts']);
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-28
      • 1970-01-01
      • 2018-04-28
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多