|
1 | 1 | --- |
2 | 2 | title: Including Client-Side Resources |
3 | 3 | page_title: Copying Client-Side Resources |
4 | | -description: "Get started with Telerik UI for ASP.NET Core and learn about different ways of copying the client-side resources into Telerik UI for ASP.NET Core project." |
| 4 | +description: "Get started with Telerik UI for ASP.NET Core and learn about the different ways of copying the client-side resources into a Telerik UI for ASP.NET Core project." |
5 | 5 | previous_url: /aspnetmvc-apps/mvc-6/getting-started-vscode, /mvc-6/getting-started-vscode, /getting-started/getting-started-copy-client-resources, /getting-started/installation/getting-started-copy-client-resources |
6 | 6 | slug: copyclientresources_aspnetmvc6_aspnetmvc |
7 | 7 | position: 6 |
@@ -97,6 +97,112 @@ To include the client-side resources, use any of the following approaches: |
97 | 97 | ... |
98 | 98 | </head> |
99 | 99 |
|
| 100 | +{% if site.core %} |
| 101 | +## Using LibMan |
| 102 | + |
| 103 | +[Library Manager (LibMan)](https://docs.microsoft.com/en-us/aspnet/core/client-side/libman/?view=aspnetcore-5.0) is a client-side library management tool. The supported CDNs include [CDNJS](https://cdnjs.com/), [jsDelivr](https://www.jsdelivr.com/), and [unpkg](https://unpkg.com/#/). The selected library files are fetched and placed in the specified location within the ASP.NET Core project. |
| 104 | + |
| 105 | +The following guide shows how to include the client-side resources by using LibMan: |
| 106 | + |
| 107 | +1. Add a `libman.json` file to your ASP.NET Core application following the [Microsoft guidelines](https://docs.microsoft.com/en-us/aspnet/core/client-side/libman/libman-vs?view=aspnetcore-5.0). |
| 108 | +1. Add the following configuration to the `libman.json` file to fetch the library in the specified destination: |
| 109 | + |
| 110 | + ```libman.json |
| 111 | + { |
| 112 | + "version": "1.0", |
| 113 | + "defaultProvider": "cdnjs", |
| 114 | + "libraries": [ |
| 115 | + { |
| 116 | + "provider": "unpkg", |
| 117 | + "library": "@progress/[email protected]", |
| 118 | + "destination": "wwwroot/lib/kendo-ui/2021.3.914" |
| 119 | + } |
| 120 | + ] |
| 121 | + } |
| 122 | + ``` |
| 123 | + |
| 124 | + > This step uses unpkg to load the Kendo UI library distributed on NPM. [The scripts in the NPM package are not usable in the browser]({% slug npmpackages_core %}#kendo-ui-professional-on-npm). This requires you to use a bundler such as [WebPack](https://webpack.js.org/). |
| 125 | + |
| 126 | +1. Add the following files, containing the configurations provided below: |
| 127 | + * `webpack.config.js` and `package.json` files to the **wwwroot** folder of the application. |
| 128 | + * `entry.js` file in the **wwwroot/js/** folder to specify the scripts that should be bundled. |
| 129 | + |
| 130 | + ```webpack.config.js |
| 131 | + const path = require('path'); |
| 132 | + var webpack = require("webpack"); |
| 133 | + |
| 134 | + module.exports = { |
| 135 | + plugins: [ |
| 136 | + new webpack.ProvidePlugin({ |
| 137 | + $: 'jquery', |
| 138 | + }) |
| 139 | + ], |
| 140 | + entry: { |
| 141 | + site: './js/entry.js' |
| 142 | + }, |
| 143 | + output: { |
| 144 | + filename: 'bundle.js', |
| 145 | + path: path.resolve(__dirname, 'dist') |
| 146 | + }, |
| 147 | + resolve: { |
| 148 | + extensions: ["", ".js", "min.js"], |
| 149 | + alias: { |
| 150 | + 'jquery': path.join(__dirname, 'node_modules/jquery') |
| 151 | + } |
| 152 | + |
| 153 | + }, |
| 154 | + devtool: 'source-map', |
| 155 | + }; |
| 156 | + ``` |
| 157 | + ```package.json |
| 158 | + { |
| 159 | + "version": "1.0.0", |
| 160 | + "name": "asp.net", |
| 161 | + "private": true, |
| 162 | + "dependencies": { |
| 163 | + "jquery": "^3.6.0", |
| 164 | + "jquery-validation": "^1.19.3", |
| 165 | + "jquery-validation-unobtrusive": "^3.2.12", |
| 166 | + "bootstrap": "^4.6.0", |
| 167 | + "popper.js": "^1.16.1" |
| 168 | + }, |
| 169 | + "devDependencies": { |
| 170 | + "css-loader": "^5.2.0", |
| 171 | + "source-map-loader": "^0.1.5", |
| 172 | + "file-loader": "^6.2.0", |
| 173 | + "style-loader": "^2.0.0", |
| 174 | + "url-loader": "^4.1.1", |
| 175 | + "webpack": "^5.52.1", |
| 176 | + "webpack-cli": "^4.6.0" |
| 177 | + }, |
| 178 | + "scripts": { |
| 179 | + "build": "webpack" |
| 180 | + } |
| 181 | + } |
| 182 | + ``` |
| 183 | + ```entry.js |
| 184 | + require("jquery") |
| 185 | + window.$ = window.jQuery = $ |
| 186 | + |
| 187 | + require("../lib/kendo-ui/2021.3.914/js/kendo.all") |
| 188 | + require("../lib/kendo-ui/2021.3.914/js/kendo.aspnetmvc") |
| 189 | + ``` |
| 190 | + |
| 191 | +1. Once LibMan has fetched the Kendo UI client-side files, navigate to the **wwwroot** folder and execute the following commands: |
| 192 | + * `npm install` to install the dependencies in the local **node_modules** folder. |
| 193 | + * `npm run build` to bundle the scripts specified in the `entry.js` file. |
| 194 | + |
| 195 | + The result of the bundling will be a `bundle.js` file output in the **wwwroot/dist/** folder. |
| 196 | + |
| 197 | +1. In the `_Layout.cshtml`, file add a reference to the desired theme and the bundled scripts: |
| 198 | + |
| 199 | + ```_Layout.cshtml |
| 200 | + <link rel="stylesheet" href="~/lib/kendo-ui/2021.3.914/css/web/kendo.default-v2.css" /> |
| 201 | + <script src="~/dist/bundle.js"></script> |
| 202 | + ``` |
| 203 | + |
| 204 | +{% endif %} |
| 205 | + |
100 | 206 | ## See Also |
101 | 207 |
|
102 | 208 | * [Introduction to Telerik UI for ASP.NET Core]({% slug overview_aspnetmvc6_aspnetmvc %}) |
|
0 commit comments