WebOptimizer icon indicating copy to clipboard operation
WebOptimizer copied to clipboard

Clarification on how to disable for Development environment

Open henriquebelotto opened this issue 4 years ago • 1 comments

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

henriquebelotto avatar Jun 16 '21 16:06 henriquebelotto

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);

andycook71 avatar Jun 22 '21 03:06 andycook71