使用 Visual Studio 2015 在 gulp 中检测发布/调试 [英] Detect release / debug in gulp using Visual Studio 2015

查看:31
本文介绍了使用 Visual Studio 2015 在 gulp 中检测发布/调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 中设置了一个 ASP.NET 5 项目并创建了一个 gulpfile.js,我用它来构建我的打字稿和更少的文件.

I've set up an ASP.NET 5 project in Visual Studio and created a gulpfile.js which I use to build my typescript and less files.

对于发布版本,我想丑化和合并我的 javascripts,而对于调试,我想在我的输出文件夹中包含我的打字稿和地图.

For release builds, I want to uglify and concat my javascripts, and for debug I want to include my typescript- and maps in my output folder.

有没有办法告诉"吞下当前配置?我看到有人提到设置 NODE_ENV 环境变量,但到目前为止,我看到的解决方案并不是最佳的;他们需要在启动 IDE 等之前使用命令行.

Is there a way to 'tell' gulp the current configuration? I've seen some mention of setting the NODE_ENV environment variable, but thus far the solutions I've seen arent optimal; they require using the command line before starting the IDE, etc.

我见过的最接近的解决方案在这里:http://www.colinsalmcorner.com/post/gulp--workaround-for-handling-vs-solution-configuration

The closest solution I've seen is here: http://www.colinsalmcorner.com/post/gulp--workaround-for-handling-vs-solution-configuration

但是,这确实意味着我无法再使用 IDE 中内置的 Task Runner Explorer

This does, however, mean that I can no longer utilize the Task Runner Explorer which is built-in in the IDE

推荐答案

我知道这已经有一段时间了,但我最近遇到了同样的问题,并且对我在 SO 上的答案中找到的其他解决方案和解决方法不满意.我在aspnet github页面的评论中找到了一个非常好的解决方案:https://github.com/aspnet/Home/issues/1231#issuecomment-182017985

I know this has been around for awhile but I recently ran into the same issue and was unhappy with the other solutions and workarounds that I found in answers here on SO. I found a very nice solution that we went with in the comments on the aspnet github page: https://github.com/aspnet/Home/issues/1231#issuecomment-182017985

我希望它可以帮助人们比我更快地找到他们更满意的解决方案.

I hope that it helps someone get to a solution they're happier with faster than I did.

只需将以下行添加到项目配置中的预构建事件

Simply, add the following line to your pre-build event in project config

echo {"config" : "$(ConfigurationName)"} > ../buildConfig.json

坐在身边的那个小美女可以在您的任务中阅读它并做出相应的反应.当我处于调试模式时,我使用它来防止缩小文件,如下所示:

With that little beauty sitting around you can read it in your tasks and react accordingly. I use it to prevent minifying files when I'm in debug mode like so:

gulp.task("min:js:bundlesFolder", function ()
    {
        var json = fs.readFileSync("./buildConfig.json", "utf8");
        var host = JSON.parse(json.replace(/^uFEFF/, ''));
        host.isDebug = host.config == "Debug";
        console.log(host.isDebug);
        if (host.isDebug === true)
        {
            return;
        }
        return gulp.src([paths.jsbundleFolder + "/**/*.js", "!" + paths.jsbundleFolder + "/**/*.min.js"])
        .pipe(uglify())
        .pipe(gulp.dest(paths.jsbundleFolder));
    });

这篇关于使用 Visual Studio 2015 在 gulp 中检测发布/调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆