Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property: injectGlobalPaths doesn't take into account @use rules #70

Open
lennu opened this issue Nov 16, 2021 · 4 comments
Open

Property: injectGlobalPaths doesn't take into account @use rules #70

lennu opened this issue Nov 16, 2021 · 4 comments
Labels
Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team

Comments

@lennu
Copy link

lennu commented Nov 16, 2021

Lets say I have the following setup:

{
  injectGlobalPaths: ['./mixins.scss']
}
### mixins.scss
@mixin whatever {
  margin: 0;
}
### styles.scss
use "sass:math";

div {
  width: math.div(100, 2);
}

This will end up with error: @use rules must be written before any other rules.
https://sass-lang.com/documentation/at-rules/use

The code which adds the import statements, should analyze the file and add import clauses under @use statements instead of just adding them to beginning of the each file.

return `@import "${injectGlobalPath}"${importTerminator}`;

@andrejpavlovic
Copy link

As a workaround I removed the use of injectGlobalPaths and now import global scss files (such as mixins.scss) directly inside of component styles (such as styles.scss).

@A143447
Copy link

A143447 commented Nov 29, 2021

Our workaround was to create a workaround-scss file that performs the calculations, assigning them to variables and importing that file in the mixins.scss. It's a bit of a hack, we only had seven instances where that calculation was needed (as opposed to many more .scss files)

@r3dDoX
Copy link

r3dDoX commented Jan 28, 2022

Just ran in the same issue. Since we have quite a big project these workarounds are not a good option for us. Is anyone working on this?

@rwaskiewicz rwaskiewicz added the Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team label Jul 8, 2022
@nickjwilde
Copy link

nickjwilde commented Oct 7, 2022

We had this same issue as well. Looking into @lennu reference to

return `@import "${injectGlobalPath}"${importTerminator}`;

Switching that line to

return `@use "${injectGlobalPath}"${importTerminator}`;

Worked for me. However, this makes injected global paths use a namespace, so

'src/global/colors.scss'

Ends up with a colors namespace as per docs https://sass-lang.com/documentation/at-rules/use#choosing-a-namespace

Using

return `@use "${injectGlobalPath}" as *${importTerminator}`;

Removes the namespace if that's needed to make updating easier/more seamless.

I'd be happy to help with this issue.

Edits: formatting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team
Projects
None yet
Development

No branches or pull requests

6 participants