-
Notifications
You must be signed in to change notification settings - Fork 0
Developer Notes
To include JavaScript libraries, we use Bower instead of NuGet because of multiple reasons:
- most of the JavaScript libraries are not present on NuGet;
- even if the libraries are present, most of the time they are outdated;
- download libraries were stored in the project's source code repository.
New ASP.NET Core project templates use Bower from scratch. But the UXR Web is still an ASP.NET MVC 5 app. ASP.NET MVC 5 projects originally use Bundles specified in BundleConfig.cs file which are then referenced in Razor views.
Grunt replaces this bundling process. To retain referencing of bundles in Razor views, we need to sync BundlesConfig with Grunt bundling output. Instead of doing this manually, we use an approach described in the following blog posts and GitHub repository by Jon Smith:
- Introduction to Bower, Grunt and Gulp in Visual Studio
- Introduction to Bundler4Bower for ASP.NET MVC5
- MvcUsingBower Git repository
Following these posts and example project, these changes were made in the UXR project:
- added reference to the Bundler4Bower package from NuGet,
- added BowerBundles.json which specifies bundles.
- added BowerBundlerHelper that is used in the Razor views.
Bundler4Bower may be removed if it brings any problems. Here are resources which do not use Bundler4Bower:
- 'ASP.NET MVC Using bower/grunt/wiredep to inject javascript dependencies into BundleConfig.cs' by Robert Noack
- 'Getting started with Bower on an ASP.NET MVC project' by Joe Wilson
- 'Using Grunt' in ASP.NET Core docs
Yes, Gulp is another option instead of Grunt. Gulp is used in ASP.NET Core projects and may replace Grunt.
- 'Control how your bower packages are installed with a gulpfile in ASP.NET 5' by Scott Hanselman
- 'ASP.NET 5 MVC bundling & minification with Gulp, NPM and Bower' by Rudi Visser
- 'Where Did My ASP.NET Bundles Go in ASP.NET 5?' by Jeff Fritz
- 'Manage Client-Side Packages with Bower' in ASP.NET Core docs
- Node.js Tools for Visual Studio