如何在Visual Studio 2017上将通过NPM安装的库包含到我的MVC项目中

时间:2023-01-13 11:27:10

I am trying to move from Bower to NPM.

我正试图从Bower转向NPM。

While I was using Bower, it was easy to configure the .bowerrc file and have the downloaded libraries in a directory such as wwwroot/lib

当我使用Bower时,很容易配置.bowerrc文件并将下载的库放在诸如wwwroot / lib之类的目录中

Now, I am developing a ASP.Net Core MVC app and trying to use NPM as my default package manager. By using Command Line in Visual Studio 2017, NPM creates package.json file and download libraries to node_modules folder. Then, what is next? How can I get JS or CSS files like I used to have in wwwroot/lib director?

现在,我正在开发一个ASP.Net核心MVC应用程序,并尝试使用NPM作为我的默认包管理器。通过在Visual Studio 2017中使用命令行,NPM创建package.json文件并将库下载到node_modules文件夹。接下来是什么?我怎样才能获得像以前在wwwroot / lib director中那样的JS或CSS文件?

1 个解决方案

#1


1  

Ok, so heres' the thing.

好的,所以继承人的事情。

NPM: Node JS package manager, helps you to manage all the libraries your software relays on. You would define your needs in a file called package.json and run npm install in the command line... BANG your packages are downloaded and are ready to use. Could be used both for front-end and back-end.

NPM:Node JS包管理器,可帮助您管理软件中继的所有库。您可以在名为package.json的文件中定义您的需求,并在命令行中运行npm install ... BANG您的软件包已下载并可以使用了。可以用于前端和后端。

resource: https://www.quora.com/What-are-the-differences-between-NPM-Bower-Grunt-Gulp-Webpack-Browserify-Slush-Yeoman-and-Express

Now, here's where NPM stops and his dear friend Gulp takes over. I can't type all of it, but to have your css and js files in a folder (and do whatever you want with them) you'll have to use an automation tool (I personally use Gulp but there's a bunch of them out there).

现在,这是NPM停止的地方,他亲爱的朋友Gulp接管了。我无法输入所有内容,但是要将css和js文件放在一个文件夹中(并随心所欲地执行任何操作),您将不得不使用自动化工具(我个人使用Gulp但是有一大堆出来那里)。

It's easy to set up and the documentation is here: https://gulpjs.com/

它很容易设置,文档在这里:https://gulpjs.com/

Gulp will basically be responsible of how and where your css files get compiled. It will base its requests for packages in the node_modules folder. So you're good to go. Configure gulp and you should be on your way.

Gulp将主要负责编译css文件的方式和位置。它将基于node_modules文件夹中的包请求。所以你很高兴。配置gulp,你应该在路上。

There's also webpack. Never used it, but it seems to be the future of automation:

还有webpack。从未使用它,但似乎是自动化的未来:

https://webpack.js.org/

I'd suggest using webpack.

我建议使用webpack。

#1


1  

Ok, so heres' the thing.

好的,所以继承人的事情。

NPM: Node JS package manager, helps you to manage all the libraries your software relays on. You would define your needs in a file called package.json and run npm install in the command line... BANG your packages are downloaded and are ready to use. Could be used both for front-end and back-end.

NPM:Node JS包管理器,可帮助您管理软件中继的所有库。您可以在名为package.json的文件中定义您的需求,并在命令行中运行npm install ... BANG您的软件包已下载并可以使用了。可以用于前端和后端。

resource: https://www.quora.com/What-are-the-differences-between-NPM-Bower-Grunt-Gulp-Webpack-Browserify-Slush-Yeoman-and-Express

Now, here's where NPM stops and his dear friend Gulp takes over. I can't type all of it, but to have your css and js files in a folder (and do whatever you want with them) you'll have to use an automation tool (I personally use Gulp but there's a bunch of them out there).

现在,这是NPM停止的地方,他亲爱的朋友Gulp接管了。我无法输入所有内容,但是要将css和js文件放在一个文件夹中(并随心所欲地执行任何操作),您将不得不使用自动化工具(我个人使用Gulp但是有一大堆出来那里)。

It's easy to set up and the documentation is here: https://gulpjs.com/

它很容易设置,文档在这里:https://gulpjs.com/

Gulp will basically be responsible of how and where your css files get compiled. It will base its requests for packages in the node_modules folder. So you're good to go. Configure gulp and you should be on your way.

Gulp将主要负责编译css文件的方式和位置。它将基于node_modules文件夹中的包请求。所以你很高兴。配置gulp,你应该在路上。

There's also webpack. Never used it, but it seems to be the future of automation:

还有webpack。从未使用它,但似乎是自动化的未来:

https://webpack.js.org/

I'd suggest using webpack.

我建议使用webpack。