Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stylesheets and scripts bundles not working in Mono

Background: I am migrating an ASP.NET MVC 5 application (developed in Windows 8.1, VS2013 Community, .NET 4.5.1, MySql custom membership and role provider) project to Monodevelop (in Ubuntu 14.4, Monodevelop, Mono).

In my ~/App_Start/BundleConfig class

public static void RegisterBundles(BundleCollection bundles)
    {
        BundleTable.EnableOptimizations = true;

     bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css"));

        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));
    }

In my ~/Views/Shared/_Layout.cshtml view

@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")

In my Web.Config

<add namespace="System.Web.Optimization" />

Also

<compilation defaultLanguage="C#" debug="false"> </compilation>

Also Microsoft.Web.Infrastructure.dll is deleted from the bin directory.

Problem: I don't see that the bundles are getting rendered when I view source in the browser:

The links are directing towards directories, It should show files in the directories

<link href="/Content/css" rel="stylesheet"/>
<script src="/bundles/modernizr"></script>

This bundling is working very fine on Windows but on Ubuntu, I see only directories

What am I doing wrong here?

like image 359
xameeramir Avatar asked May 28 '15 06:05

xameeramir


People also ask

What is the benefit of bundling .JS scripts into one file?

Bundling reduces the number of individual HTTP requests to server by combining multiple CSS files and Javascript files into single CSS file and javascript file. Minification reduces the file download size of CSS and javascript files by removing whitespace, comments and other unnecessary characters.

What is a script bundle?

The ScriptBundle class represents a bundle that does JavaScript minification and bundling. You can create style or script bundles in BundleConfig class under App_Start folder in an ASP.NET MVC project.

What is bundling in CSS?

Bundling is the process of rolling up a number of distinct resources together into a single downloadable resource. For example, a bundle may consist of multiple JavaScript or CSS files you bring down to the local machine by making a single HTTP request to an ad hoc endpoint.

How do I use stylesheets with a stylebundle?

For stylesheets you will have to use a StyleBundle and @Styles.Render (). Instead of loading each script or style with a single request (with script or link tags), all files are compressed into a single JavaScript or stylesheet file and loaded together.

What is the difference between stylebundle and scriptbundle?

ASP.NET MVC API includes StyleBundle class that does CSS minification and bundling. StyleBundle is also derived from a Bundle class so it supports same methods as ScriptBundle.

Why are @import rules not working in my stylesheet?

If @import rules are present in a constructable stylesheet, those rules will be ignored. Support for @import in CSS module scripts may be added to the specification. Track this specification discussion in the GitHub issue.

Where do I create a style bundle?

Same as the script bundle, all the style bundles should be created in the BundleConfig class. under the App_Start folder. The following example shows how to combine multiple CSS files into a bundle.


1 Answers

Inside your BundleConfig file add the following:

BundleTable.EnableOptimizations = true;

Then switch to release mode.

This should do the trick

like image 61
Mihai Tibrea Avatar answered Oct 07 '22 14:10

Mihai Tibrea