Yang
Yang

Reputation: 63

Asp.Net Core 2.1 Static Files

Normally we are link the css with like

<environment include="Development">
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
        <link rel="stylesheet" href="~/css/site.css" />
        <link rel="stylesheet" href="~/css/IndexCss.css" />
    </environment>

But can i just link the folder ? Cus have too many css need to link ... Or any suggustion

Upvotes: 2

Views: 321

Answers (1)

Serj Sagan
Serj Sagan

Reputation: 30208

ASP.NET Core MVC comes with a built in bundler and minifier so that many CSS files can become one, also does the same for JavaScript files.

Just create a file called bundleconfig.json at the root of the project with content like this:

[
  {
    "outputFileName": "wwwroot/css/site.min.css",
    "inputFiles": [
      "~/lib/bootstrap/dist/css/bootstrap.css",
      "~/css/*.css"
    ]
  },
  {
    "outputFileName": "wwwroot/js/site.min.js",
    "inputFiles": [
      "~/js/*.js"
    ],
    "minify": {
      "enabled": true,
      "renameLocals": true
    },
    "sourceMap": false
  }
]

More info here: https://learn.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification?view=aspnetcore-2.2&tabs=visual-studio

Upvotes: 3

Related Questions