angular-material-css-vars icon indicating copy to clipboard operation
angular-material-css-vars copied to clipboard

SCSS Import

Open paul-wade opened this issue 3 years ago • 1 comments

I'm wondering if I have messed something up.

The only way I can import the material-css-vars main file is by using this import @import 'angular-material-css-vars/src/lib/_main';

Has something changed and the documentation is out of date with the latest version of angular?

paul-wade avatar Feb 17 '22 18:02 paul-wade

It shouldn't have as far as I am aware. In my case

@import '~angular-material-css-vars/src/lib/main';

and

@import '~angular-material-css-vars/src/lib/_main';

both work.

johannesjo avatar Feb 18 '22 12:02 johannesjo

@paul-wade I have the same problems with the scss import. Used to work <3.0.0, but now the issue will be solved in #103

maxfriedmann avatar Jan 05 '23 17:01 maxfriedmann

Should be fixed with version v4.0.1 via #110.

json-derulo avatar Jan 09 '23 16:01 json-derulo

@johannesjo @json-derulo I don't think this has truly been fixed. Neither @use or @import 'angular-material-css-vars/src/lib/main' work on version 4.0.2 at the moment. They display "can't find stylesheet" errors when you try to build with the "build-angular:browser" builder for applications.

Now, 'angular-material-css-vars/main' does work with the browser builder. However, 'angular-material-css-vars/main' does not work when trying to build an angular library, which is built with the "build-angular:ng-packagr" builder. ng-packagr will only build successfully with 'angular-material-css-vars/src/lib/main'.

This creates a catch 22 for developers who have an angular application as well as angular libraries that the applications uses. As it stands right now, you can't successfully build both your application and angular libraries with version 4.0.2. ng-packagr(builds library) ignores sass exports while the export section(which is recognized by the application builder) only accepts imports that match exactly.

Maybe it should be it's own issue but it seemed related to this post. But I would like if you updated package.json's recently added export section to also include './src/lib/main', '.src/lib/public-util' and './src/lib/variables' paths as well. That should solve the problem in theory, though I'd probably be the first to test and confirm with my application should that update get implemented. But if there are other workarounds or solutions that you know, I'm all ears.

crose9876 avatar Jan 27 '23 22:01 crose9876

@crose9876 This seems to be related to the following issue: https://github.com/ng-packagr/ng-packagr/issues/1631

Is it an option for you to provide the related SCSS code as an asset? I don't see a particular reason why ng-packagr needs to compile any angular-material-css-vars related SCSS, it should be possible to do this at a later point when building the applications, which would avoid the issue.

json-derulo avatar Jan 28 '23 13:01 json-derulo

@json-derulo In this case, the scss code in question is in component scss files, so it seems like it may be harder to provide those files to assets in ng-package.json. I still need to take some time to see if that solution would work though I'm skeptical.

crose9876 avatar Jan 30 '23 19:01 crose9876

Is there some workaround for this? We are updating angular to version 14, and this issue is a big blocker for us. I'm willing to help and have already tried something but haven't been successful.

Wlada avatar Jan 31 '23 15:01 Wlada

@Wlada your issue is unrelated, you need to use v3.x with Angular 14.

json-derulo avatar Feb 01 '23 15:02 json-derulo

I've looked into the potential assets solution/workaround. And it doesn't look think it'll work. My library has a lot of component.scss files that needs to import/use 'angular-material-css-vars/variables' or 'angular-material-css-vars/public-util'. The components will be compiled when building the library with ng-packagr and I'm not sure how to get around that.

The solution I know that would work would be including the src/lib paths(not in place of the shortcut paths but in addition to) in exports in package.json as I mentioned earlier.

However, I'll continue to look into other potential solutions in case you guys don't think that's a good idea. Still I'm all ears when it comes to any kind of workaround.

crose9876 avatar Feb 02 '23 20:02 crose9876

@crose9876 @johannesjo The issue with ng-packagr is tackled by #119

json-derulo avatar Feb 04 '23 13:02 json-derulo

Thank you very much @json-derulo !!!

johannesjo avatar Feb 07 '23 15:02 johannesjo

@crose9876 With v5 there is a new feature that you can use a single entrypoint. You just have to import like the following: @use "angular-material-css-vars" as mat-css-vars, and you can use all the available mixins and variables. I think this should also work in your library use case. Could you check this?

json-derulo avatar May 04 '23 18:05 json-derulo

I won't be able to check this at the moment as my project is still on Angular 15 and I wouldn't be able to use v5 until I upgrade to 16. When I can upgrade to 16, I'll check then. Sorry about that.

crose9876 avatar May 04 '23 19:05 crose9876

@crose9876 No worries, there is no rush :) Thanks in advance!

json-derulo avatar May 04 '23 19:05 json-derulo