How to share styles across publishable libs? #22622
Replies: 97 comments 7 replies
-
I'm facing the same issue! For example I have one specific library e.g: "subscriptions". I would like to publish that library to re-usable into a legacy project that my company still maintains. However, that library can't have any other dependency inside my new Nx workspace |
Beta Was this translation helpful? Give feedback.
-
I ran into this same issue.
This is related to the discussion in #1542 |
Beta Was this translation helpful? Give feedback.
-
Same issue here. I have started a monorepo project and am trying to use the variables from the shared "styles" library inside another library. Are there any updates on how this should be best handled? |
Beta Was this translation helpful? Give feedback.
-
I have the same issue. In my humble opinion, this is a pretty standard use-case (having a styles lib shared across apps/libs). We have a huge nx workspace and rebuilds sometime take up to 2mins, so I decided to take advantage of incremental build using buildable libs. Unfortunately, the build fails do the reason mentioned in the first post. |
Beta Was this translation helpful? Give feedback.
-
I am also facing this issue. Only when building a buildable lib that uses a shared style sheet. |
Beta Was this translation helpful? Give feedback.
-
I just posted on the nrwl/community slack my opinion that syncing/linking your included package with the top-level stylePreprocessorOptions feels wrong, because it requires a developer inside the monorepo to be a monorepo developer (e.g. to figure out what a relative path is relative to) and this will be a bigger issue imho as Nx embraces a bigger tent of applications. On the flip side, I'm not sure how that would tie in as Nx reaches beyond JS/TS... |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
Beta Was this translation helpful? Give feedback.
-
I believe this is still an issue. |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
Beta Was this translation helpful? Give feedback.
-
This is still an issue to my knowledge. |
Beta Was this translation helpful? Give feedback.
-
I am also running into this exact use-case. I want to use NX to manage a component library. It should also expose global css (for example for theming), much like Angular Material does. Right now, it does not seem feasible to have a publishable library per component which use shared styles. |
Beta Was this translation helpful? Give feedback.
-
Same. This is a common use case when styles apply across multiple libs (e.g. |
Beta Was this translation helpful? Give feedback.
-
Honestly, I think we should have a built-in "@nrwl/angular:style-library" schematic or something like that. Having to guess and try various things is disappointing |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
Beta Was this translation helpful? Give feedback.
-
This is still an issue |
Beta Was this translation helpful? Give feedback.
-
I also haven't found a solution to this problem. Currently moving from a vue 2 project to a vue 3 project, and I haven't found any solution as to sharing stylesheets from libraries to apps. |
Beta Was this translation helpful? Give feedback.
-
+1 still useful feature would be |
Beta Was this translation helpful? Give feedback.
-
for what it is worth, i added a scss import from the main "APP" to the shared ui lib styles.scss file like:
While the styles are built into the app, the styles get rebuilt with every change during nx serve. I tried adding the |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
Beta Was this translation helpful? Give feedback.
-
this is still a valid problem without any satisfying solution |
Beta Was this translation helpful? Give feedback.
-
How come this thing is not solved for an absolutely must-have feature? I managed to make it work only with relative path. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I've converted this to a discussion so it can take advantage of Github features there. I'm having trouble discerning some actionable request here. While sharing styles is important, there are many ways to go about it. Compiling a globals.css to be included for many different components is very different than writing sass modules which can be reused in other sass code. Along with this general discussion, I feel like it may be useful to open new discussions about distinct use cases. I think from those more focused discussions, they have a higher chance of yielding actionable ways which Nx can help here. |
Beta Was this translation helpful? Give feedback.
-
My main use case is that I have material like components, that use the theme your own components aproch. Here I want to have my scss mixin to be imported the same way I would the component. By writing |
Beta Was this translation helpful? Give feedback.
-
they have a nice defacto standard for assets here and I thought back when this vid was created there was a complimentary video for styles too so I designed my own called @nhhockeyplayer/shared-root-ui-styles funny thing is I cannot
styles or stylePreprocessorOptions is this a design shortfall? did I create my @nhhockeyplayer/shared-root-ui-styles for nothing? or is this thread dedicated for this omission |
Beta Was this translation helpful? Give feedback.
-
these kinds of imports are a violation this should have been solved years ago whats going on Nx team? Im ahead of the steam and cannot run with this yet my SASS design system cannot even be shared across Nx libraries ? this is NOT Nx culture ethics or standards and should be fixed immediately can anyone give a status on this please workaround? is anybody home? |
Beta Was this translation helpful? Give feedback.
-
Maybe this solution will be useful to someone: To import global layout css in your project my-app: apps/my-app/src/styles.css We define the path to the global css file in the tsconfig.base.json:
Make sure to add in my-app project.json::
|
Beta Was this translation helpful? Give feedback.
-
Frustrating that there's still no solution for this all these years later. |
Beta Was this translation helpful? Give feedback.
-
Solution for Nx (v20.0.0) and Angular (v18.1.1) Project with SCSS ConfigurationIf you're working with a project structure similar to the one below and want to configure SCSS across your Angular apps and shared libraries, here's a working setup. Project Structure:
Configuration Steps:
|
Beta Was this translation helpful? Give feedback.
-
We have been able to configure our libraries to use absolute imports using stylePreprocessorOptions to the point where the app serves using nx serve (although we have had to turn off the warnings in the IDE), but the app fails to build using nx build. Sass is throwing "Can't find stylesheet to import" errors. Has anyone else got to this stage and has any experience of getting the build to work? We are using esbuild, Angular v18, Nx v20. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Description
I have a monolithic app and now I split it into publishable libs which I am going to use in that app.
There are some common styles like variables and mixing in main app. And I want to reuse that styles into my libs.
I have tried to move styles into separate lib and I was able to reuse them in main app through configuration in angular.json (
stylePreprocessorOptions
) but I can't use these styles in other libraries.Is there any ideas how can I manage this situation?
Beta Was this translation helpful? Give feedback.
All reactions