Posted by Anuraj on Wednesday, November 7, 2018 Reading time :3 minutes
This post is about working with both libman and dotnet bundle commands. Libman aka Microsoft Library Manager, helps developers to install and consume 3rd-party client-side libraries with ease. And dotnet bundle command helps to minify and combines multiple files into a single file.
libman is a new global CLI tool, which you can install using
dotnet tool install -g Microsoft.Web.LibraryManager.CLI command. Once you install the tool, you will be able to run
libman from command line to install different script packages.
Like npm or bower, libman also uses a configuration file -
libman.json, which helps developers to configure which all packages, version, download location, files etc.
Here is an example
defaultProvider is the library provider it could be either
unpkg. And the libraries element is array, where you can provide the library name and version, the destination element specifies to which directory the downloaded files to be saved.
Even though ASP.NET Core MVC template coming with different client side libraries, it is missing the
libman.json file. Here is the
libman.json file for ASP.NET Core MVC template.
In this Dockerfile, I am installing the libman as global tool, then adding the tools path to the PATH environment variable and restoring the packages before building the ASP.NET Core project.
ASP.NET Core MVC template comes with site.min.js and site.min.css files, but these files are minified versions of site.js and site.css files, but how these files are getting generated? Unlike earlier versions of ASP.NET MVC, there is no in built mechanism to do minification in ASP.NET Core, you need to use different tools. One of commonly used to tool is
BuildBundlerMinifier. This one is not a dotnet global tool, you need to add it using the following command -
dotnet add package BuildBundlerMinifier. Once you install this tool, unlike libman, this tool will run along with
dotnet build command. Here is
bundleconfig.json file for ASP.NET Core MVC project.
Then if you’re running the command
dotnet build, you will be able to see bundling and minification in action.
Similar to the above answer, I don’t recommend this approach, because there is no point in keeping minified versions of files in source control. In one of the project I reviewed, I found the lead developer is only committing the minified version of the file to source control. You should commit the actual un minified source to source control. Minification and bundling should be part of build script or deployment script.
Here is the
.gitignore file for ASP.NET MVC Core template file.
I faced the above challenges while docker-ising an ASP.NET Core MVC application. Using the above mentioned will help you to avoid issues which can occur while deploying an ASP.NET Core MVC app.
Happy Programming :)