-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(turbopack): initial sass-loader support (#49882)
<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation or adding/fixing Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### Why? ### How? Closes NEXT- Fixes # --> ### What? WEB-654. This PR attempts to implement initial sass support in turbopack, via sass-loadder. Internally it points to sass-loader compiled in next.js (`next/dist/sass-loader..`) with next.config.js's option. Still it is not a complete implementation, for example sourceMap is not supported by upstream turbopack. PR requires turbopack side changes as well.
- Loading branch information
Showing
8 changed files
with
60 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use anyhow::Result; | ||
use turbo_tasks::primitives::JsonValueVc; | ||
use turbopack_binding::turbopack::{ | ||
node::transforms::webpack::{WebpackLoaderConfigItem, WebpackLoaderConfigItemsVc}, | ||
turbopack::module_options::WebpackLoadersOptionsVc, | ||
}; | ||
|
||
#[turbo_tasks::function] | ||
pub async fn maybe_add_sass_loader( | ||
sass_options: JsonValueVc, | ||
webpack_options: WebpackLoadersOptionsVc, | ||
) -> Result<WebpackLoadersOptionsVc> { | ||
let mut options = (*webpack_options.await?).clone(); | ||
|
||
let sass_options = sass_options.await?.as_object().unwrap().clone(); | ||
for ext in [".scss", ".sass"] { | ||
let loader = WebpackLoaderConfigItem::LoaderNameWithOptions { | ||
loader: "next/dist/compiled/sass-loader".to_string(), | ||
options: serde_json::json!({ | ||
//https://github.com/vercel/turbo/blob/d527eb54be384a4658243304cecd547d09c05c6b/crates/turbopack-node/src/transforms/webpack.rs#L191 | ||
"sourceMap": false, | ||
"sassOptions": sass_options, | ||
}) | ||
.as_object() | ||
.unwrap() | ||
.clone(), | ||
}; | ||
|
||
options.extension_to_loaders.insert( | ||
ext.to_owned(), | ||
if options.extension_to_loaders.contains_key(ext) { | ||
let mut new_configs = (*(options.extension_to_loaders[ext].await?)).clone(); | ||
new_configs.push(loader); | ||
WebpackLoaderConfigItemsVc::cell(new_configs) | ||
} else { | ||
WebpackLoaderConfigItemsVc::cell(vec![loader]) | ||
}, | ||
); | ||
} | ||
|
||
Ok(options.cell()) | ||
} |
4 changes: 0 additions & 4 deletions
4
...es/next-swc/crates/next-dev-tests/tests/integration/turbopack/sass/warning/input/index.js
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.