WebOptimizer
WebOptimizer copied to clipboard
Clarification on how to disable for Development environment
Hello,
In the documentation it mentions that I have to add the code below to disable the features to development.
if (env.IsDevelopment())
{
services.AddWebOptimizer(minifyJavaScript:false,minifyCss:false);
}
However, "services" is not available here
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
neither is IWebHostEnvironment env here
public void ConfigureServices(IServiceCollection services)
(Startup.cs class).
So, I'm not sure how to disable it for development. Could someone clarify it?
Thank you
I stored a reference in the constructor:
public IWebHostEnvironment Environment { get; set; }
public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
Configuration = configuration;
Environment = env;
}
then you can say:
var isDevelopment = Environment.IsDevelopment();
services.AddWebOptimizer(minifyJavaScript:isDevelopment, minifyCss:isDevelopment);