Problem with Bundle scripts

Asked

Viewed 596 times

2

When I publish my Asp.net mvc application the Bundle script generates a ref. scripts problem.

As in the debug environment 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.white wing:

        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"));
  • You can add the rest of your global.asax please?

  • I changed, it’s all there!

  • Your scripts are extending the same property twice (or more), so the warning. Your browser inspector hints which script is?

  • In the script Select2

1 answer

2


I solved the problem by creating the virtuais path of bundles in accordance with the 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 that folder and when you load an image in a css included in that Folder, for example, it will use that folder as the initial path. In my case it was the javascript that load a resource and could not!

Unfortunately the Asp.NET MVC along with his System.Web.Optimization uses virtual path as if it were a real path that gets in the way of internal css or Java resource load.

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 having to organize the files and paths of the external resources manually.
  • Create several Bundles for each plugin that makes use of external resources like images and fonts, increasing the amount of requests.

Good Asp.NET xD MVC!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.