ligershark / WebOptimizer

A bundler and minifier for ASP.NET Core
Apache License 2.0
753 stars 113 forks source link

Unable to minify assets outside of wwwroot with custom path? #256

Open kendallb opened 1 year ago

kendallb commented 1 year ago

In our code we have Javascript and CSS files that we deploy alongside each view at times. It makes it simpler to simply reference the files from the view directory so we can keep things that are view specific out of the main Javascript bundles, however if I enable minification of Javascript files it will always fail on those files if I have this enabled. I am setting up ASP.NET Core 6 to serve the files from the Views directory automatically with those code:

        // Enable static files and also enable serving them from the /Views directories for view specific content files
        app.UseStaticFiles();
        var viewsPath = Path.Combine(env.ContentRootPath, "Views");
        app.UseStaticFiles(new StaticFileOptions {
            FileProvider = new PhysicalFileProvider(viewsPath),
            RequestPath = new PathString("/Views"),
        });

But if I simply allow it to minify JS files verbatim, it will always fail on that file when minification is enabled in production mode. So for now I use this to do it only on stuff in wwwroot/css and wwwroot/js, but ideally I would like to figure out how to get WebOptimizer to properly support minifying those files? Ideally once this is working, I would probably want to inline that CSS and Javascript into those pages as it's usually quite small and would be nice to not have another request for those pages.

        if (!isDevelopment) {
            pipeline.MinifyCssFiles("css/**/*.css");
            pipeline.MinifyJsFiles("js/**/*.js");
        }

We are in the process of porting all our code from ASP.NET 4.8 to ASP.NET Core 6. For our primary web site we usually end up adding them to a bundle, so if it cannot find the files to minify them it likely won't be able to find them to put into a bundle either. Hence the reason I would like to get this fixed so we can both minify them (or inline them) if they are not in a bundle, or add them to bundles at startup time automatically.

Worst case I guess I can clone them into an identical structure under wwwroot during application deployment, but that would not be as optimal.

RoopKanwar31 commented 1 year ago

Any update on the fix of this issue? Having a similar use case where the requirement is to minify the resources outside wwwroot folder.

kendallb commented 1 year ago

Not that I am aware of :(