1

I'm learning Scott Allen - ASP.Net Core Fundamental course from Pluralsight and trying to add the external library from Node_Modules to my project.

Here is the project's structure:

enter image description here

And how I including datatable library to my project (adding to Pages/Shared/_Layout.cshtml) enter image description here

But when the app is running, it cannot find these libraries: enter image description here

Questions:

  1. What wrong with this way ?
  2. Can you guys suggest some effective ways to import external libraries to ASP.NET CORE app?

I'm using .NET 5

<PropertyGroup>
   <TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
3
  • 2
    You don't serve the contents of node_modules directly to website visitors. Instead your application's build process will run tools like Gulp, WebPack, Uglify, Rollup, etc which produce compact (minified) JS which will be in your /scripts or /dist folder to be served. (Of course integrating an npm build with MSBuild can be complicated). Commented Dec 16, 2020 at 0:42
  • The problem with the JavaScript developer ecosystem is that it's incredibly fast-moving - pretty much everything I learned even 2-3 years ago is irrelevant now (e.g. I knew AngularJS in 2015 but all that knowledge was obsolete when Angular2 came out; and everything I thought I knew about Grunt and Babel in 2017 is moot now - it's a lot of work to keep up, unfortunately) Commented Dec 16, 2020 at 0:49
  • Yeah, the technologies change so fast, need to keep learning and updating every day and cannot escape Commented Dec 16, 2020 at 23:07

2 Answers 2

0

Please note that the default directory that we store static files is {content root}/wwwroot, you can move these datatables plugin related js&css files to web root directory.

For more information about serving static files in ASP.NET Core, please check this doc:

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-5.0

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Fei Han, I solved my problem from your document.
0

From the document provided by Fei Han I solved my problem. I need add some config to include "node_modules" as PhysicalFileProvider in Startup.cs file like below: enter image description here

and then update src and href attribute in script/link tag:

<script src="~/StaticFiles/datatables.net/js/jquery.dataTables.js"></script>
<link href="~/StaticFiles/datatables.net-bs4/css/dataTables.bootstrap4.css" rel="stylesheet"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.