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: improve sass compilation #109

Merged
merged 7 commits into from
Jan 9, 2023
Merged

Conversation

dwightjack
Copy link
Contributor

This PR should fix nuxt/module-builder#67 and add some improvements to the sass loader.

Changes:

  • sass files are always renamed to CSS ignoring passed-in options.ext. I don't see any use case where we'd want an extensions different from .css since sass loader compiles the source to CSS.
  • add support for @use and @import rules in sass and Vue SFC files.
  • by default, always skip copying and compiling sass files starting with _ because they are sass partials.

src/loaders/sass.ts Outdated Show resolved Hide resolved
const compileString = await import("sass").then(r => r.compileString || r.default.compileString);

const output: LoaderResult = [];

const contents = await input.getContents();

output.push({
contents: compileString(contents).css,
contents: compileString(contents, { loadPaths: [dirname(input.srcPath)] }).css,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

loadPaths is required to enable relative imports (sass/sass#3366 (comment))

Copy link
Member

@cpreston321 cpreston321 Jan 3, 2023

Choose a reason for hiding this comment

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

@dwightjack what about adding 'node_modules' ? Just in case we want to add @use '@external-node-module/style.css'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cpreston321 thanks for your feedback. I update the PR including node_modules and added a test (0141120).

Copy link
Member

@cpreston321 cpreston321 Jan 4, 2023

Choose a reason for hiding this comment

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

Hey @dwightjack I appreciate it! ✅ It would be nice to see in the future to see options that we can pass the sass complier like compressed: true etc.

@codecov
Copy link

codecov bot commented Dec 22, 2022

Codecov Report

Merging #109 (51527dc) into main (338f65f) will increase coverage by 0.14%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #109      +/-   ##
==========================================
+ Coverage   95.95%   96.09%   +0.14%     
==========================================
  Files           8        8              
  Lines         470      487      +17     
  Branches       96       98       +2     
==========================================
+ Hits          451      468      +17     
  Misses         19       19              
Impacted Files Coverage Δ
src/loaders/sass.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@cpreston321
Copy link
Member

@manniL Think we can get some eyes on this ? 🙏🏼

@TheAlexLichter TheAlexLichter requested a review from pi0 January 4, 2023 15:22
@dwightjack
Copy link
Contributor Author

dwightjack commented Jan 4, 2023

@cpreston321 (cc @manniL) thanks! While I confirmed that the latest changes to load from node_modules work in the tests, some in depth check would be vpery welcome and appreciated, because I admit it feels "too easy" to just add "node_modules" to the load path (and not, for example, an absolute path) 😅 .

About this comment, i guess that implementing a feature such as configurable loaders would be helpful, but it is, in my opinion, a pretty important change so I'd like to have feedback from the maintainers about this.
Another options might be to implement hooks like in unbuild 🤔

Another note: since the PR might need some more reviews and implementations, what about moving this change to another small PR so that we can close nuxt/module-builder#67 once published?

@cpreston321
Copy link
Member

@dwightjack

  1. That's kinda what I was thinking 🤔

  2. Makes 💯% since, I was kinda thinking out loud!

  3. I agree -- if you want to make another PR you can or it can be a solve for another time. So this one can be knocked out.

@dwightjack dwightjack force-pushed the feat/sass-improvements branch from 0141120 to cb0ee73 Compare January 6, 2023 10:17
@dwightjack
Copy link
Contributor Author

@cpreston321 sorry for the late reply. I extracted the file extension fix to another PR (#111) and rebased this PR onto the main branch without that change.

@pi0
Copy link
Member

pi0 commented Jan 6, 2023

Do you mind to rebase PR?

@hoersamu
Copy link

hoersamu commented Jan 9, 2023

Any progress with this? I'm happy to help if there are open tasks.

@pi0 pi0 changed the title Feat: improve sass compilation feat: improve sass compilation Jan 9, 2023
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

💯 Thanks!

@pi0 pi0 merged commit bc9536a into unjs:main Jan 9, 2023
@dwightjack
Copy link
Contributor Author

@pi0 sorry, had a rough few days and hadn't the chance to work on this. Thanks for merging the PR. Let me know if there's anything else I could do to improve this feature. Of course I am available to work on other issues as well 😃

@pi0
Copy link
Member

pi0 commented Jan 9, 2023

No problems. I hope you have better days ahead 💚 And for sure looking forward for your next amazing works 🚀

@hoersamu
Copy link

hoersamu commented Jan 9, 2023

Thanks guys :D
@pi0 when do you think we can expect the next release?

@dwightjack dwightjack deleted the feat/sass-improvements branch January 10, 2023 02:14
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.

SCSS files get renamed with *.mjs extension
4 participants