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

fix sass handling after refactoring #50259

Merged
merged 2 commits into from
May 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/next-swc/crates/next-core/src/sass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ pub async fn maybe_add_sass_loader(
} else {
Default::default()
};
for pattern in ["*.scss", "*.sass"] {
for (pattern, rename) in [
("*.module.scss", ".module.css"),
("*.module.sass", ".module.css"),
("*.scss", ".css"),
("*.sass", ".css"),
] {
let rule = rules.get_mut(pattern);
let loader = WebpackLoaderItem {
loader: "next/dist/compiled/sass-loader".to_string(),
Expand All @@ -37,12 +42,17 @@ pub async fn maybe_add_sass_loader(
let mut loaders = rule.loaders.await?.clone_value();
loaders.push(loader);
rule.loaders = WebpackLoaderItemsVc::cell(loaders);
if let Some(rename_as) = rule.rename_as.as_mut() {
rename_as.push_str(rename);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain this, I don't understand why we would append to an already established rename rule? Should this be an error case?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I guess we should not apply our sass logic when the rename_as is used.

e. g. they could

// apply their own sass transform
"*.sass": {
  loader: ["sass-loader"],
  as: "*.css"
}
// convert to js
"*.sass": {
  loader: ["sass-to-js-loader"],
  as: "*.js"
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll fix it in a separate PR

} else {
rule.rename_as = Some(format!("*{rename}"));
}
} else {
rules.insert(
pattern.to_string(),
LoaderRuleItem {
loaders: WebpackLoaderItemsVc::cell(vec![loader]),
rename_as: Some("*".to_string()),
rename_as: Some(format!("*{rename}")),
},
);
}
Expand Down