How do I include libraries that installed via NPM to my MVC project on Visual Studio 2017

让人想犯罪 __ 提交于 2019-12-08 17:38:22

问题


I am trying to move from Bower to 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

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?


回答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.

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).

It's easy to set up and the documentation is here: 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.

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

https://webpack.js.org/

I'd suggest using webpack.



来源:https://stackoverflow.com/questions/45907027/how-do-i-include-libraries-that-installed-via-npm-to-my-mvc-project-on-visual-st

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!