Include assets when building library using ng-packagr

Algis picture Algis · Sep 27, 2017 · Viewed 17.2k times · Source

Could anyone give a hint where to start to include images and css files into Angular library using ng-packagr?

Answer

Mahesh Kumar picture Mahesh Kumar · Feb 23, 2020

It's an old thread but still updating with a latest options in Feb-2020

With the ng-packagr ^9.0.1 version, You can do this using inbuilt "copy assets"

{
  "ngPackage": {
    "assets": [
      "CHANGELOG.md",
      "./styles/**/*.theme.scss"
    ],
    "lib": {
      ...
    }
  }
}

https://github.com/ng-packagr/ng-packagr/blob/master/docs/copy-assets.md

This has helped me remove the postpackage cp scripts

Adding my actual ng-package.json for benefit of others. I wanted to copy the assets folder and all its contents to the library and publish it along with it.

{
  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
  "dest": "../../dist/common",
  "assets": [
    "assets"
  ],
  "lib": {
    "entryFile": "src/public-api.ts",
    "umdModuleIds": {
      "common": "common"
    }
  }
}

The assets folder is in the library root directory. this helps to copy the entire assets folder and the contents inside it and add it to the library, so that you can use it as @include "@node_modules/your-library/assets/styles/main.scss"