-
Notifications
You must be signed in to change notification settings - Fork 187
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: make CSS preprocessor plugins compat with Rsbuild 1.2 #4909
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,11 +149,6 @@ export const pluginLess = ( | |
.resolve.preferRelative(true) | ||
.end(); | ||
|
||
const inlineRule = chain.module | ||
.rule(findRuleId(chain, CHAIN_ID.RULE.LESS_INLINE)) | ||
.test(include) | ||
.resourceQuery(/inline/); | ||
|
||
// Support for importing raw Less files | ||
chain.module | ||
.rule(CHAIN_ID.RULE.LESS_RAW) | ||
|
@@ -173,7 +168,15 @@ export const pluginLess = ( | |
callback: (rule: RspackChain.Rule, type: 'normal' | 'inline') => void, | ||
) => { | ||
callback(rule, 'normal'); | ||
callback(inlineRule, 'inline'); | ||
|
||
// Rsbuild < 1.3.0 does not have RULE.CSS_INLINE. | ||
if (chain.module.rules.has(CHAIN_ID.RULE.CSS_INLINE)) { | ||
const inlineRule = chain.module | ||
.rule(findRuleId(chain, CHAIN_ID.RULE.LESS_INLINE)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. findRuleId should not be put inside the updateRules method. It should be only called once. |
||
.test(include) | ||
.resourceQuery(/inline/); | ||
callback(inlineRule, 'inline'); | ||
} | ||
}; | ||
|
||
const lessLoaderPath = path.join( | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -126,11 +126,6 @@ export const pluginSass = ( | |||||
.resolve.preferRelative(true) | ||||||
.end(); | ||||||
|
||||||
const inlineRule = chain.module | ||||||
.rule(findRuleId(chain, CHAIN_ID.RULE.SASS_INLINE)) | ||||||
.test(include) | ||||||
.resourceQuery(/inline/); | ||||||
|
||||||
// Support for importing raw Sass files | ||||||
chain.module | ||||||
.rule(CHAIN_ID.RULE.SASS_RAW) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'll make a patch in the next PR
Suggested change
|
||||||
|
@@ -140,12 +135,20 @@ export const pluginSass = ( | |||||
|
||||||
// Update the normal rule and the inline rule | ||||||
const updateRules = ( | ||||||
callback: ( | ||||||
rule: RspackChain.Rule, | ||||||
type: 'normal' | 'inline', | ||||||
) => Promise<void>, | ||||||
) => | ||||||
Promise.all([callback(rule, 'normal'), callback(inlineRule, 'inline')]); | ||||||
callback: (rule: RspackChain.Rule, type: 'normal' | 'inline') => void, | ||||||
) => { | ||||||
callback(rule, 'normal'); | ||||||
|
||||||
// Rsbuild < 1.3.0 does not have RULE.CSS_INLINE. | ||||||
if (chain.module.rules.has(CHAIN_ID.RULE.CSS_INLINE)) { | ||||||
const inlineRule = chain.module | ||||||
.rule(findRuleId(chain, CHAIN_ID.RULE.SASS_INLINE)) | ||||||
.test(include) | ||||||
.resourceQuery(/inline/); | ||||||
|
||||||
callback(inlineRule, 'inline'); | ||||||
} | ||||||
}; | ||||||
|
||||||
const sassLoaderPath = path.join( | ||||||
__dirname, | ||||||
|
@@ -165,7 +168,7 @@ export const pluginSass = ( | |||||
sourceMap: false, | ||||||
}; | ||||||
|
||||||
await updateRules(async (rule, type) => { | ||||||
updateRules((rule, type) => { | ||||||
for (const item of excludes) { | ||||||
rule.exclude.add(item); | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be preferable to use
CHAIN_ID.RULE.CSS_INLINE && chain.module.rules.has(CHAIN_ID.RULE.CSS_INLINE)
because, theoretically, there could be a rule namedundefined
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be better👍