Skip to content

Commit

Permalink
fix: css 与 less 等规则没有写在一起时,只会给 css 规则增加 loader
Browse files Browse the repository at this point in the history
  • Loading branch information
meixg committed Dec 23, 2021
1 parent 9d27011 commit 621490a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,35 @@ function getLoaderByMatch(compiler: Compiler, matchExtension: string) {
* @param compiler
*/
function addStyleLoader(compiler: Compiler) {
const addedRules = new Set();
const cssRule = getLoaderByMatch(compiler, 'css');
addLoader(cssRule);

addToOptionalRule('less');
addToOptionalRule('stylus');
addToOptionalRule('styl');
addToOptionalRule('sass');
addToOptionalRule('scss');

function addToOptionalRule(rule: string) {
let optRule;
try {
optRule = getLoaderByMatch(compiler, rule);
}
catch {
}
if (optRule) {
addLoader(optRule);
}
}

function addLoader(rule: RuleSetRule) {
// 防止多次添加
if (addedRules.has(rule)) {
return;
}
addedRules.add(rule);

if (rule.oneOf) {
rule.oneOf.forEach(item => addLoader(item));
return;
Expand Down

0 comments on commit 621490a

Please sign in to comment.