Skip to content

feat(plugin-sass): add useOriginalUrlResolver option to disable resolve-url-loader #4389

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions packages/plugin-sass/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,33 @@ export const pluginSass = (
const clonedOptions = deepmerge<Record<string, any>>({}, options);

if (id === CHAIN_ID.USE.CSS) {
// add resolve-url-loader and sass-loader
clonedOptions.importLoaders += 2;
// add resolve-url-loader
if (!pluginOptions.useOriginalUrlResolver)
clonedOptions.importLoaders += 1;
// add sass-loader
clonedOptions.importLoaders += 1;
}

rule.use(id).loader(loader.get('loader')).options(clonedOptions);
}

// use resolve-url-loader if useOriginalResolver is not set
if (!pluginOptions.useOriginalUrlResolver)
rule
.use(CHAIN_ID.USE.RESOLVE_URL)
.loader(
path.join(__dirname, '../compiled/resolve-url-loader/index.js'),
)
.options({
join: await getResolveUrlJoinFn(),
// 'resolve-url-loader' relies on 'adjust-sourcemap-loader',
// it has performance regression issues in some scenarios,
// so we need to disable the sourceMap option.
sourceMap: false,
})
.end();

rule
.use(CHAIN_ID.USE.RESOLVE_URL)
.loader(path.join(__dirname, '../compiled/resolve-url-loader/index.js'))
.options({
join: await getResolveUrlJoinFn(),
// 'resolve-url-loader' relies on 'adjust-sourcemap-loader',
// it has performance regression issues in some scenarios,
// so we need to disable the sourceMap option.
sourceMap: false,
})
.end()
.use(CHAIN_ID.USE.SASS)
.loader(path.join(__dirname, '../compiled/sass-loader/index.js'))
.options(options);
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-sass/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ export type PluginSassOptions = {
* Exclude some `.scss` or `.sass` files, they will not be transformed by sass-loader.
*/
exclude?: Rspack.RuleSetCondition;

/**
* Use original url resolver instead of resolve-url-loader.
*/
useOriginalUrlResolver?: boolean;
};
8 changes: 8 additions & 0 deletions website/docs/en/plugins/list/plugin-sass.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ pluginSass({
});
```

### useOriginalUrlResolver

- **Type:** `boolean`
- **Default:** `undefined`
- **Version:** `>= 1.2.0`

Use the original resolver instead of `resolve-url-loader` when resolving urls

## Practices

### Modify Sass implementation
Expand Down
Loading