I'm trying to use stylePreprocessorOptions
in order to include a path to my variables folders for a library project like so :
"stylePreprocessorOptions": {
"includePaths": [
"styles/variables"
]
}
Then I use @import 'colors';
within the scss file. But it doesnt work while doing ng serve
:
@import 'colors';
^
Can't find stylesheet to import.
Here is the full library in angular.json :
"ui-table": {
"root": "libs/ui/table",
"sourceRoot": "libs/ui/table/src",
"projectType": "library",
"prefix": "xxx",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "libs/ui/table/tsconfig.lib.json",
"project": "libs/ui/table/ng-package.json",
"stylePreprocessorOptions": {
"includePaths": [
"styles/variables"
]
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["libs/ui/table/tsconfig.lib.json"],
"exclude": ["**/node_modules/**"]
}
}
},
"schematics": {
"@nrwl/schematics:component": {
"styleext": "scss"
}
}
},
How can I use stylePreprocessorOptions
in a library in Angular?
Thanks!
You can add more global styles via the styles option inside your project's build target options in angular. json . These will be loaded exactly as if you had added them in a <link> tag inside index.
A file named angular. json at the root level of an Angular workspace provides workspace-wide and project-specific configuration defaults for build and development tools provided by the Angular CLI. Path values given in the configuration are relative to the root workspace folder.
Not in angular.json.
Include the path to your scss folder with styleIncludePaths
in the librairies' ng-package.json
"lib": {
"entryFile": "src/public-api.ts",
...
"styleIncludePaths": [
"relative/path/to/scss/folder"
]
...
}
finally import the files from the referenced scss folder without prefix path as follows
@import "filename";
The accepted answer did not work for me using Angular v9.
But this did:
{
"ngPackage": {
"lib": {
"styleIncludePaths": ["./src/assets/styles"]
}
}
}
More details here: https://github.com/ng-packagr/ng-packagr/blob/master/docs/style-include-paths.md
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With