最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to use JavaScript NuGet libraries in ASP.Net Core project correctly on the example MathJax? - Stack Overflow

programmeradmin3浏览0评论

I installed MathJax library for my site on ASP.Net Core from Package Manager. I have seen 'MathJax (2.7.0)' in NuGet Dependencies:

Image of My Dependencies

But is it all. When I see wwwroot\lib directory in my project I don't see 'MathJax' folder or something similar in it:

Image of My fron-end lib

But when I need use MathJax I need write something similar in my html-page:

<script type="text/javascript" async src="~lib/MathJax/MathJax.js?config=TeX-AMS_HTML-full"></script>

I can't copy NuGet library directly in wwwroot\lib, because I don't want to add my git repository a lot of files external project (> 36 Mb, > 1500 files). Besides, why use NuGet then? Also, I can't add existing items of MathJax NuGet library manually (menu Add -> Existing Item...), because they are a lot and the absolute path will not correctly on another PC.

How I can get correctly link on MathJax library in NuGet package?

I installed MathJax library for my site on ASP.Net Core from Package Manager. I have seen 'MathJax (2.7.0)' in NuGet Dependencies:

Image of My Dependencies

But is it all. When I see wwwroot\lib directory in my project I don't see 'MathJax' folder or something similar in it:

Image of My fron-end lib

But when I need use MathJax I need write something similar in my html-page:

<script type="text/javascript" async src="~lib/MathJax/MathJax.js?config=TeX-AMS_HTML-full"></script>

I can't copy NuGet library directly in wwwroot\lib, because I don't want to add my git repository a lot of files external project (> 36 Mb, > 1500 files). Besides, why use NuGet then? Also, I can't add existing items of MathJax NuGet library manually (menu Add -> Existing Item...), because they are a lot and the absolute path will not correctly on another PC.

How I can get correctly link on MathJax library in NuGet package?

Share Improve this question asked Mar 29, 2019 at 10:53 V. SokolovV. Sokolov 411 silver badge3 bronze badges 1
  • Check this answer, you need to use a ConfigureOptions. – Sergio Merino Martínez Commented Mar 30, 2020 at 14:34
Add a ment  | 

3 Answers 3

Reset to default 7

The JavaScript/CSS library NuGet packages are not for Core. They're for MVC. ASP.NET Core has a pletely different approach to static files and client-side libraries than ASP.NET MVC did.

For an ASP.NET Core site, you need to use either LibMan or npm to get your client-side libraries. LibMan is easier, but also very naive and limited. In particular, it only supports libraries that are on cdnjs. While there's a lot of coverage there, it's not prehensive, and there's some libraries that just are available. I'm not sure whether your particular library is or not.

However, given that you'll almost inevitably end up needing something you can't get through LibMan, and and then you'll be forced to use npm anyways, you might as well just use npm and get used to it. There's more of a learning curve because you also need to create build tasks with something like Webpack, Gulp, Grunt, etc. The npm packages go into a node_modules folder, which should not be served directly. At the very least, you'll need to use Webpack, Gulp, etc. to copy the dist/build of the npm package (i.e. the actual JS/CSS files that you'll be referencing) into your wwwroot/lib directory. There's lots of guides online for how to set this up. Just do some research.

In the VS2019, go to the wwwroot/lib directory, right click and select Add -> Client-Side Library. then include your file.

Go to the web project, right click and go the manage client scripts, then search your library and instal.

发布评论

评论列表(0)

  1. 暂无评论