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

feat(build): support @use or @import in component styles #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gary5
Copy link

@gary5 gary5 commented Oct 3, 2024

There are errors when building if my component styles contains @use.

Failed to compile stylesheet my.component.scss sass.Exception [Error]: Can't find stylesheet to import.
  ╷
2 │ @use 'my-styles' as *;
  │ ^^^^^^^^^^^^^^^^^^^^^

I thing we need this option to help sass compile successfully.
https://nx.dev/nx-api/angular/executors/webpack-browser#stylepreprocessoroptions
https://nx.dev/nx-api/angular/executors/browser-esbuild#stylepreprocessoroptions

Copy link
Owner

@Coly010 Coly010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Thanks for the PR :)

I've one comment about documentation / implementation that conflict with each other.
To keep everything consistent, I think we should keep it relative to the project root.

I know this will be strange when the paths to include live outside the project, but we should have a way to configure that, similar to how Nx has {workspaceRoot} identifiers that can be replaced.

That way, we can check if the string starts with this then resolve to the workspace root instead.

I'm going to set up some manner of integration testing before merging this too, so we can ensure that current use cases continue to work.

Once I have that integration testing set up, we can add a test case in this PR to ensure that this works as expected.

"type": "object",
"properties": {
"includePaths": {
"description": "Paths to include. Paths will be resolved to project root.",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mentions paths being resolved to project root, but the implementation in createConfig is joining the workspaceRoot, not the project root.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment.

I am not sure why the schema of stylePreprocessorOptions defined in angular/executors/webpack-browser.json is described relative to project root, but most of other paths are relative to workspace root.

Here is the one I should copy from angular/executors/browser-esbuild.json

"stylePreprocessorOptions": {
  "description": "Options to pass to style preprocessors.",
  "type": "object",
  "properties": {
    "includePaths": {
      "description": "Paths to include. Paths will be resolved to workspace root.",
      "...
    }
  },
  ...
},

From my thought, it looks not strange to set the path outside the project. If we leverage and keep the consistence of the path design among other executors, it will benefit people to migrate from webspack or esbuild more easily.

Weather to change the path design from relative to project root to workspace root or not, I will fix my mistake of inconsistence first.

@gary5 gary5 force-pushed the main branch 5 times, most recently from ae0c14d to 46383dc Compare October 9, 2024 05:18
@gary5
Copy link
Author

gary5 commented Oct 9, 2024

Hi,
I update the PR to make the path consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants