Skip to content

libman.json Extension #368

Description

@jzabroski

Hi @madskristensen

I would like to make the pipeline itself Watch-able through a FileWatcher on a libman.json file. This would allow people using libman to define assets to watch for, and simplify some configuration.

This would effectively allow WebOptimizer to be used outside of a IIS or Kestrel context and allow for precompilation, competing directly with Rich's MapStaticAssets approach introduced in .NET 9 c.f. #335 and address my questions here about pre-caching the results to feed into a dotnet pack operation: #344

libman.json - Extension Example 1 - explicit Bundles

  "buildOptions": {
    "bundles": [
      {
        "name": "vendor-scripts",
        "outputPath": "wwwroot/bundles/vendor.min.js",
        "files": [
          "wwwroot/lib/jquery/dist/jquery.min.js",
          "wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.min.js"
        ],
        "minify": true,
        "sourceMap": true
      },
      {
        "name": "vendor-styles",
        "outputPath": "wwwroot/bundles/vendor.min.css",
        "files": [
          "wwwroot/lib/bootstrap/dist/css/bootstrap.min.css"
        ],
        "minify": true,
        "sourceMap": false
      }
    ],
    "globalMinifyOptions": {
      "removeComments": true,
      "preserveLicenses": true,
      "mangle": false
    }
  }

libman.json - Extension Example 2 - Destinations as Bundles

  "buildOptions": {
    "destinationsAsBundles": true,
    "globalMinifyOptions": {
      "removeComments": true,
      "preserveLicenses": true,
      "mangle": false
    }
  }
  1. Assumes files collection is an ordered list of dependencies.
  2. Use last folder path in destination as namespace for bundle file naming convention e.g. "destination": "wwwroot/lib/jquery" maps to the bundle name jquery.
{
  "library": "jquery@3.7.1",
  "destination": "wwwroot/lib/jquery/",
  "files": [
    "jquery.js"
  ]
},
{
  "library": "jquery-ajax-unobtrusive@3.2.6",
  "destination": "wwwroot/lib/jquery/",
  "files": [
    "jquery.unobtrusive-ajax.js"
  ]
}

libman.json - Extension Example 3 - Bundle Path

  1. May want bundles to live outside wwwroot as they many be ephemeral in nature, would not want to write these to disk in wwwroot and end up with strange, difficult to reproduce bugs
  "buildOptions": {
    "bundlePath": "~/bundles",
    "destinationsAsBundles": true,
    "globalMinifyOptions": {
      "removeComments": true,
      "preserveLicenses": true,
      "mangle": false
    }
  }

This would result in the asset being resolvable as:

<script src="~/bundles/jquery" type="text/javascript" />

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions