1

For example if I have the following structure:

component-library > src > lib

Inside the lib folder I have a styles folder and a button component folder

Now in the styles folder I have declared a styles.scss file and a mixins folder.

In the mixins folder I declare some mixins which I then import to use in the button component as well as other components but the issue I am facing right now is that every time I run ng-build to build the lib.

Errors are being thrown. for example:

ERROR: Undefined mixin. ╷ 7 │ @include mixin-name; │ ^^^^^^^^^^^^^^^^^^^^^ ╵

src\lib\button\button.component.scss 7:3 root stylesheet An unhandled exception occurred: Undefined mixin. ╷ 7 │ @include button-reset; │ ^^^^^^^^^^^^^^^^^^^^^ ╵

What do I need to configure different to achieve this as if I was ng building an actual angular application? I have read that library is built differently compared to the actual app.

Any solutions to get around this or do I need a different approach to this? Like for example wherever I need to use that mixin, I'd need to duplicate the styles multiple times in every component?

1 Answer 1

1

After digging around especially on github. It was suggested that issues is not related to anglar or the cli itself but rather ng-packagr and the way it bundles the files when you execute the command ng build.....

From this link to ng-packagr copy assets, they suggest adding the following to the library's ng-package.json:

{
    "$schema": ".....",
    "dest": "......",
    "assets": "src/lib/assets/styles/mixins/<filename>.theme.scss"
}

That way I can still use and import the mixins into the components. The above will successfully resolve, the errors and will build successfully.

Much better from ng-packagr team, spent the last few days fluffing about trying to come up with a working script to try and achieve this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.