The question. How can I add to Startup.cs (ASP.NET Core project) same configuration as I was doing with App_Start > BundleConfig.cs
When having:
public class BundleConfig
{
// For more information on bundling, visit http://go.microsoft.com
/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
and then:
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
for example...
Click on wwwroot folder, select the css file you want minified, then right click and choose bundler & minifier. Then from popup minify file. It will be the same file name with the minified version. Also generate bundleconfig.
Bundling and minification is enabled or disabled by setting the value of the debug attribute in the compilation Element in the Web. config file. In the following XML, debug is set to true so bundling and minification is disabled. To enable bundling and minification, set the debug value to "false".
Bundling and minification are two techniques you can use in ASP.NET to improve page load performance for your web application. Bundling combines multiple files into a single file. Minification performs a variety of different code optimizations to scripts and CSS, which results in smaller payloads.
Bundling and Minification as it existed in MVC5 no longer exists in MVC Core.
Your options are (without delving into the Node ecosystem - which is just as valid but would introduce more concepts):
Both of these tools operate on the same infrastructure under the covers. They use a bundleConfig.json
file to describe the structure of your bundles (what files go in, what file comes out, wether to include sourcemaps, etc.)
Explanations of these two concepts are also available via the documentation.
Instead of having a call to @Scripts.Render()
which would produce links to either minified or unminified resources depending on your build environment, you can use taghelpers
to swap between links to minified and unminified resources. For example:
<environment names="Development">
<script src="~/unminified.js"></script>
</environment>
<environment names="Staging,Production">
<script src="~/bundledandminified.min.js"></script>
</environment>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With