What is the right approach for doing this?
There are a lot of "right" approaches, you just have decide which one best suites your needs. It appears as though you're misunderstanding how to use node_modules
...
If you're familiar with NuGet you should think of npm as its client-side counterpart. Where the node_modules
directory is like the bin
directory for NuGet. The idea is that this directory is just a common location for storing packages, in my opinion it is better to take a dependency
on the packages you need as you have done in the package.json
. Then use a task runner like Gulp
for example to copy the files you need into your desired wwwroot
location.
I wrote a blog post about this back in January that details npm, Gulp and a whole bunch of other details that are still relevant today. Additionally, someone called attention to my SO question I asked and ultimately answered myself here, which is probably helpful.
I created a Gist
that shows the gulpfile.js
as an example.
In your Startup.cs
it is still important to use static files:
app.UseStaticFiles();
This will ensure that your application can access what it needs.