Reputation:
How do I convert the following BundleConfig.cs into BundleConfig.json? I am migrating a .NET 4.6.2 project into NET ASP Core 2. Received errors below, and trying to research. Was also trying to read microsoft documents https://learn.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification?view=aspnetcore-2.2&tabs=visual-studio
Original BundleConfig.cs
namespace Test.Web
{
/// <summary>
/// Bundle configs registration common class.
/// </summary>
public class BundleConfig
{
/// <summary>
/// Register Bundles.
/// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
/// </summary>
/// <param name="bundles"></param>
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/misc/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/misc/bootstrap.js",
"~/Scripts/misc/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
}
}
Attempted Solution: Starts in Third Paragraph
[
{
"outputFileName": "wwwroot/css/site.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/js/site.min.js",
"inputFiles": [
"wwwroot/js/site.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optionally generate .map file
"sourceMap": false
},
{
"outputFileName": "~/bundles/jquery",
"inputFiles": [
"\"~/Scripts/jquery/jquery-{version}.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optionally generate .map file
"sourceMap": false
},
Received error:
Value must match regular expression \.css$
Value must match regular expression \.js$
Upvotes: 3
Views: 5679
Reputation: 1116
Your "outputFileName" should be ending with either .js or .css.
Just change
"outputFileName": "~/bundles/jquery",
to
"outputFileName": "wwwroot/Scripts/bundles/jquery.js",
and it won't show that error. Also in .net core, all the static files are served from wwwroot folder, so you should change "~/bundles/" to "wwwroot/bundles/BundleName.js" or "wwwroot/Scripts/bundles/BundlesName.js".
Upvotes: 1