Reputation: 87
I need to migrate bundleConfig from an old asp.net project mvc to asp.net core
I added in startup.cs:
app.UseBundling (
// as we rebased the static files to / static (see UseStaticFiles ()),
// we need to pass this information to the bundling middleware as well,
// otherwise urls would be rewrited incorrectly
new BundlingOptions
{
StaticFilesRequestPath = "/static"
},
bundles =>
{
bundles.AddJs ("/bundles /jquery")
.Include ("/Scripts/jquery-{version}.js");
bundles.AddCss ("/bundles/jquery")
.Include ("/Scripts/jquery-{version}.js");
// we use LESS in this demo
bundles.AddCss ("/site.css")
.Include ("/less/site.less");
// defines a Javascript bundle containing your Vue application and components
bundles.AddJs ("/app.js")
.Include ("/js/components /*.Js")
.Include ("/js/app.js");
});
Upvotes: 2
Views: 3735
Reputation: 2807
If you are using .Net core, bundleconfig.cs
is gone.
Follow the steps below to add bundling and minification
bundleconfig.json
to you solution[ { "outputFileName": "wwwroot/bundles/bootstrap", "inputFiles": [ "Scripts/bootstrap.js" ] }, { "outputFileName": "wwwroot/css/site.min.css", "inputFiles": [ "wwwroot/css/site.css", "Content/bootstrap.css" ], "minify": { "enabled": true, "renameLocals": true }, "sourceMap": false }, { "outputFileName": "wwwroot/js/semantic.validation.min.js", "inputFiles": [ "wwwroot/js/semantic.validation.js" ], "minify": { "enabled": true, "renameLocals": true } } ]
Upvotes: 1
Reputation: 333
You would have to create a cs file in App_Start
using System.Web.Optimization;
namespace EnterYourProgramsNameSpaceHere
{
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
//Add your bundles here
bundles.Add(new StyleBundle("~/Content/myStyle")
.Include("~/Content/styles.css"));
bundles.Add(new ScriptBundle("~/bundles/myjs")
.Include("~/Scripts/jquery.js"));
}
}
}
in startup.cs add this line
BundleConfig.RegisterBundles(BundleTable.Bundles);
You have to make sure that the spacing in your file paths is removed, in your example the program may have an issue finding your js/css files.
you can look up more info here : http://go.microsoft.com/fwlink/?LinkId=301862
Upvotes: -2