WebOptimizer
WebOptimizer copied to clipboard
Serving static files from node_modules and wwwroot FileNotFound Due to tagHelpers
.NET Core 5.0.4 LigerShark.WebOptimizer.Core 3.0.311
I have aproject where I serve static files from both wwwroot and node_modules folders.
For bundling I'm using ContentRoot();
services.AddWebOptimizer(pipeline =>
{
pipeline.AddCssBundle("/css/vendor.bundle.css",
"/node_modules/font-awesome/css/font-awesome.min.css",
"/node_modules/busy-load/dist/app.css",
"/node_modules/datatables.net-bs4/css/dataTables.bootstrap4.css",
"/node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css")
.UseContentRoot();
pipeline.AddJavaScriptBundle("/js/vendor1.bundle.js",
"/node_modules/jquery/dist/jquery.min.js",
"/node_modules/bootstrap/dist/js/bootstrap.min.js",
"/node_modules/busy-load/dist/app.min.js",
"/node_modules/chart.js/dist/chart.min.js",
"/node_modules/moment/min/moment.min.js"
)
.UseContentRoot();
pipeline.AddJavaScriptBundle("/js/vendor2.bundle.js",
"/node_modules/chartjs-adapter-moment/dist/chartjs-adapter-moment.min.js",
"/node_modules/datatables.net/js/jquery.dataTables.js",
"/node_modules/datatables.net-bs4/js/dataTables.bootstrap4.js",
"/node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js",
"/node_modules/xlsx/dist/xlsx.full.min.js"
)
.UseContentRoot();
pipeline.MinifyCssFiles();
pipeline.MinifyJsFiles();
});
This works as expected
But If I serve a file directly without bundling like so:
<script src="~/node_modules/jquery-ui-dist/jquery-ui.min.js"></script>
I get an error:
FileNotFoundException: No files found matching "/node_modules/jquery-ui-dist/jquery-ui.min.js" exist in "C:\Users\...\...\...\...\ProjectName\wwwroot\"
Is this the work of the tag helpers? I tried removing MinifyJsFiles() from the pipeline but the error persists.
It appears the problem is caused by the WebOptimizer tag helpers, if I remove them the error goes away. Is there a way to configure them to contentRoot or to use absolute paths?
If i remove the tag helpers then I'll loos cache busting on the bundles.