I am working on Aspnet Core Web Application with Angular 2. Since Angular 2 Requires node modules, we install the dependencies using package.json.
But it creates the folder in solution level. Since AspnetCore application reference can access only the wwwroot folder each and every time we tend to copy the node modules folder manually to wwwroot folder.
This approach should be fine as long as we are not adding a new dependency. but if we keep on adding new packages then it will be painful to copy manually every time.
Any solution for this ?
Asked
Active
Viewed 3,308 times
2

Julian
- 33,915
- 22
- 119
- 174

Vigneshwaran Markandan
- 947
- 1
- 16
- 37
-
Possible duplicate of [Exclude non-minified files from publish in \`project.json\` with ASP.NET Core](https://stackoverflow.com/questions/38370823/exclude-non-minified-files-from-publish-in-project-json-with-asp-net-core) – Tseng Jul 26 '17 at 05:56
1 Answers
2
I wouldn't copy the node_modules
to the wwwroot
folder, because it also contains a lot of stuff you'll never need. Usually you copy just the needed stuff to the wwwroot
. The best way to do so, is using Webpack. I wrote some lines about it in that posts:
- http://asp.net-hacker.rocks/2016/09/19/aspnetcore-and-angular2-using-dotnetcli-and-vscode.html
- http://asp.net-hacker.rocks/2016/09/19/aspnetcore-and-angular2-using-dotnetcli-and-vscode.html
This posts are using Angular2, and are outdated, but the concepts of using Webpack are still the same.
Another option is to use grunt or gulp to copy just the needed JavaScript files to wwwroot
:
Hope this helps
This is a pretty cool starter pack to setup a new project using ASP.NET Core and Angular: https://github.com/damienbod/AngularWebpackVisualStudio

Juergen Gutsch
- 1,774
- 2
- 17
- 28
-
I followed [this](https://medium.com/@levifuller/building-an-angular-application-with-asp-net-core-in-visual-studio-2017-visualized-f4b163830eaa) let me know is it make helpful for building large applications. and I want to set angular `index.html` in asp.net core `index.cshtml` how could I achieve this. – k11k2 Jul 26 '17 at 06:17
-
want to remove index.html file in angular2 and add those files asp.net core `index.cshtml` is it possible? – k11k2 Jul 26 '17 at 06:30
-
yes, that's possible. You just need to copy the stuff from the index.html to the _layout.cshtml and the index.cshtml. But from my perspective this only makes sense, if you want to do authentication via MVC. Usually a Single Page Application is just a HTML page, a lot of JavaScript stuff and authenticated REST based services in the background. – Juergen Gutsch Jul 26 '17 at 06:48
-
Yes, for authentication purpose only. I'm unable to sort [this](https://stackoverflow.com/questions/44818526/setting-hidden-text-from-server-node-jsexpress-asp-net-core-to-read-it-from-cl) so using `cshtml` as home for angular 2 would make me help(guess). as you said I referred the index files in `cshtml` but no luck – k11k2 Jul 26 '17 at 06:55
-
Sonds like path/reference issues. did you have a look into the browsers dev tools to see what happens? – Juergen Gutsch Jul 26 '17 at 07:27
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/150152/discussion-between-k11k2-and-juergen-gutsch). – k11k2 Jul 26 '17 at 07:57