0

I have a Web Application hosted in Azure.

It's configured to automatically build and deploy from the GitHub repository.

I was using a version of angular.min.js which I had installed from a nuget package, and then directly checked in. Now I want to change this, and incorporate javascript packages from npm instead of nuget.

I did the following:

  • Added an npm configuration file
  • Add the dependency "angular": "^1.6.5"

Here's the complete package.json file:

{
   "version": "1.0.0",
   "name: "asp.net",
   "private": true,
   "dependencies": {
      "angular": "^1.6.5"
   },
   "devDependencies": {}
}

Then, in my razor page, I referenced angular directly from the node_modules folder:

<script type="text/javascript" src="~/node_modules/angular/angular.min.js"></script>

This worked on my local machine. I checked this into Github, and the Azure framework built and deployed my code. However, the folder node_modules is not present under D:\home\site\wwwroot

I tried added a pre-build step:

npm install

but this did not solve the problem.

Using kudu, I bought up the debug console on the web server. I set the location to the folder D:\home\site\wwwroot, then typed npm install. This worked: it created and populated the node_modules folder, and my website could now access the angular file.

So, either the build is not restoring the packages, or it is restoring the packages but not deploying them to the wwwroot folder.

Is there a correct way to include javascript files from node packages in ASP.NET MVC apps on Azure?

2 Answers 2

1

I added a post-deploy step, following the instructions on this page.

  • In the browser, go to https://<mywebappname>.scm.azurewebsites.net
  • Activate the Debug Console \ Powershell tab
  • Drill to the folder "D:\home\site\deployments\tools"
  • Create a folder "PostDeploymentActions"
  • In this folder, add a powershell script post-deploy.ps1:

The contents of this powershell script:

pushd d:\home\site\wwwroot
npm install
popd

Now the node packages are installed on the web server with each deployment.


At this stage, I'm not sure whether this is the best long-term solution or not....

Sign up to request clarification or add additional context in comments.

Comments

0

As a best practice when using GitHub for continuous deployment, we recommend using Custom Deployment Script for customizing the deployment process. Please check this doc out for details.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.