Skip to content

Instantly share code, notes, and snippets.

@farukcan
Created October 20, 2022 23:36
Show Gist options
  • Save farukcan/c7316642ca8daec01f653864f2043f71 to your computer and use it in GitHub Desktop.
Save farukcan/c7316642ca8daec01f653864f2043f71 to your computer and use it in GitHub Desktop.
Use npm and asp dotnet together

use node_modules folder as static folder /lib

app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "node_modules")),
    RequestPath = "/lib",
        
    OnPrepareResponse = ctx =>
    {
        ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=600");
    }
});

npm commands

npm init --yes
npm i jquery bootstrap jquery-validation jquery-validation-unobtrusive -s

sample package.json

{
  "name": "Your App",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "dotnet watch run",
    "prod": "dotnet run"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bootstrap": "^5.2.2",
    "jquery": "^3.6.1",
    "jquery-validation": "^1.19.5",
    "jquery-validation-unobtrusive": "^4.0.0"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment