From 621490a6a423f721f7341861186fa3171a8a3230 Mon Sep 17 00:00:00 2001 From: meixg Date: Thu, 23 Dec 2021 12:30:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20css=20=E4=B8=8E=20less=20=E7=AD=89?= =?UTF-8?q?=E8=A7=84=E5=88=99=E6=B2=A1=E6=9C=89=E5=86=99=E5=9C=A8=E4=B8=80?= =?UTF-8?q?=E8=B5=B7=E6=97=B6=EF=BC=8C=E5=8F=AA=E4=BC=9A=E7=BB=99=20css=20?= =?UTF-8?q?=E8=A7=84=E5=88=99=E5=A2=9E=E5=8A=A0=20loader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/plugin.ts b/src/plugin.ts index 6fecdee..7d83fad 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -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;