I am using ASP.NET Core MVC 6 using Visual Studio 2015. In my gulpfile.js script I want to know if the hosting environment is Development, Staging or Production so that I can add or remove source maps (.map files) and do other things. Is this possible?
UPDATE
Relevant issue on GitHub.
You would need to set the NODE_ENV environment variable in each environment and then in your gulpfile, read it in using process.env.NODE_ENV.
Have a look at https://stackoverflow.com/a/16979503/672859 for additional details.
You can use the
ASPNETCORE_ENVIRONMENT
(Was formerlyASPNET_ENV
in RC1) environment variable to get the environment. This can be done in your gulpfile usingprocess.env.ASPNETCORE_ENVIRONMENT
.If the environment variable does not exist, you can fallback to reading the
launchSettings.json
file which Visual Studio uses to start your application. If that also does not exist, then fallback to using the Development environment.I wrote the following JavaScript object to make dealing with the environment in gulpfile.js easier. You can find the full gulpfile.js source code here.
See this answer for how to set the environment variable.