#How do I use variables.scss in Angular Lib using ng-packagr

3 messages · Page 1 of 1 (latest)

urban veldt
#

Created a Angular Lib using the CLI. Now I'm trying to add some components and they are using some variables from a variables file, I can't find any documentation on how to add this global scss to the Angular Lib soo I can reach them from the exported components.

native ridge
wispy jackal
#

Are you asking how to include a global scss to your published package or how to import them in the library's components styles?

I assume you are wanting to publish the package, with a global scss. Since you would have a lot of redundant duplicates, if you imported it in each exported component's styles.

To include the styles in you would add the scss to the ngPackage assets:

{
  "ngPackage": {
    "assets": [
      { "input": "src/styles", "glob": "**/*.scss", "output": "styles" }
    ],
    ...
  }
}

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

Then the application, depending on the package, can add them to it's styles in angular.json:

{
  "projects": {
    "my-app": {
      "architect": {
        "build": {
          "options": {
            "styles": [
              "src/styles.scss",
              "@my-lib/dist/styles.scss"
            ]
          }
        }
      }
    }
  }
}
GitHub

Compile and package Angular libraries in Angular Package Format (APF) - ng-packagr/ng-packagr