diff --git a/src/loaders/sass/importer.ts b/src/loaders/sass/importer.ts index 749e55f4..a3a865db 100644 --- a/src/loaders/sass/importer.ts +++ b/src/loaders/sass/importer.ts @@ -1,8 +1,9 @@ import path from "path"; -import { resolveAsync, resolveSync } from "../../utils/resolve"; +import { packageFilterBuiler, resolveAsync, resolveSync } from "../../utils/resolve"; import { getUrlOfPartial, isModule, normalizeUrl } from "../../utils/url"; const extensions = [".scss", ".sass", ".css"]; +const conditions = ["sass", "style"]; export const importer: sass.Importer = (url, importer, done): void => { const finalize = (id: string): void => done({ file: id.replace(/\.css$/i, "") }); @@ -11,7 +12,12 @@ export const importer: sass.Importer = (url, importer, done): void => { if (!isModule(url)) return next(); const moduleUrl = normalizeUrl(url); const partialUrl = getUrlOfPartial(moduleUrl); - const options = { caller: "Sass importer", basedirs: [path.dirname(importer)], extensions }; + const options = { + caller: "Sass importer", + basedirs: [path.dirname(importer)], + extensions, + packageFilter: packageFilterBuiler({ conditions }), + }; // Give precedence to importing a partial resolveAsync([partialUrl, moduleUrl], options).then(finalize).catch(next); }; @@ -21,7 +27,12 @@ export const importerSync: sass.Importer = (url, importer): sass.Data => { if (!isModule(url)) return null; const moduleUrl = normalizeUrl(url); const partialUrl = getUrlOfPartial(moduleUrl); - const options = { caller: "Sass importer", basedirs: [path.dirname(importer)], extensions }; + const options = { + caller: "Sass importer", + basedirs: [path.dirname(importer)], + extensions, + packageFilter: packageFilterBuiler({ conditions }), + }; // Give precedence to importing a partial try { return finalize(resolveSync([partialUrl, moduleUrl], options));