Problem with bundle scripts

2

When I publish my asp.net mvc application the bundle script generates a ref problem. scripts.

As in the debug environment I do not use the bundles, the problem does not happen.

Error:

  

"common / scripts": Duplicate data property in object literal not allowed in strict mode.

Global.asa white:

        ViewEngines.Engines.Clear();
        ViewEngines.Engines.Add(new RazorViewEngine());

        ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder());

        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterAuth();

        BundleTable.EnableOptimizations = !HttpContext.Current.IsDebuggingEnabled;

Bundle Register:

bundles.Add(new ScriptBundle("~/base/scripts").Include("~/Scripts/Site.js"));
bundles.Add(new ScriptBundle("~/modernizr").Include("~/Scripts/modernizr-2.7.2.js"));
bundles.Add(new ScriptBundle("~/metro/scripts").Include("~/Scripts/Metro/metro.js"));
bundles.Add(new ScriptBundle("~/jquery/scripts").Include("~/Scripts/jquery-2.1.1.js", "~/Scripts/jquery-migrate-1.2.1.js", "~/Scripts/jquery.unobtrusive-ajax.js", "~/Scripts/jquery-ui-1.10.4.js", "~/Scripts/jquery.validate.js", "~/Scripts/jquery.validate.unobtrusive.js"));
bundles.Add(new ScriptBundle("~/common/scripts").Include("~/Scripts/Common/jquery.ui.dialogr.js", "~/Scripts/Common/jquery.select2.js", "~/Scripts/Common/jquery.maskedinput.js", "~/Scripts/Common/jquery.number.js", "~/Scripts/Common/jquery.float-thead.js", "~/Scripts/Common/jquery.tablesorter.js"));
    
asked by anonymous 03.09.2014 / 14:31

1 answer

2

I solved the problem by creating virtuais path of bundles according to pastas físicas .

For example:

bundles.Add(new StyleBundle("~/content/css/metro").Include("~/Content/Css/metro-bootstrap.css", "~/Content/Css/metro-bootstrap-responsive.css", "~/Content/Css/iconFont.css"));
  

~ / content / css - indicates that the files are in this folder and when loading an image into a css included in that bundle, for example, it will use this folder as the initial path. In my case it was the javascript that did the load of a resource and could not!

Unfortunately Asp.NET MVC together with its System.Web.Optimization uses the virtual path as if it were a real path that ends up disturbing the load of internal resources of css or javascripts.

We have two options in this case:

  • Create a standardization of the css files, scripts, fonts and images in the project, losing the biggest advantage of Nuget and every update has to organize the files and paths of external resources manually.
  • Create multiple bundles for each plugin that makes use of external resources such as images and fonts, increasing the number of requests.

Good Asp.NET MVC xD!

    
03.09.2014 / 22:14