From fc97fe0b2db1720546957af1b4cd964f89cb382d Mon Sep 17 00:00:00 2001 From: noyobo Date: Wed, 27 Sep 2023 14:53:27 +0800 Subject: [PATCH] fix: ignore css include absolute files --- __tests__/css/__snapshots__/index.test.ts.snap | 1 + __tests__/css/index.css | 2 ++ __tests__/less/__snapshots__/index.test.ts.snap | 1 + __tests__/less/index.less | 1 + src/index.ts | 4 ++++ 5 files changed, 9 insertions(+) diff --git a/__tests__/css/__snapshots__/index.test.ts.snap b/__tests__/css/__snapshots__/index.test.ts.snap index 026ebc9..c92698c 100644 --- a/__tests__/css/__snapshots__/index.test.ts.snap +++ b/__tests__/css/__snapshots__/index.test.ts.snap @@ -51,6 +51,7 @@ exports[`css style-loader 2`] = ` } .title { color: #000; + background-image: url(/static/img/logo.png); font-size: 20px; } @font-face { diff --git a/__tests__/css/index.css b/__tests__/css/index.css index 57530e1..6197949 100644 --- a/__tests__/css/index.css +++ b/__tests__/css/index.css @@ -6,6 +6,8 @@ .title { font-size: 20px; color: #000; + /* ignore root files*/ + background-image: url("/static/img/logo.png"); } diff --git a/__tests__/less/__snapshots__/index.test.ts.snap b/__tests__/less/__snapshots__/index.test.ts.snap index bb58b7f..cd1407d 100644 --- a/__tests__/less/__snapshots__/index.test.ts.snap +++ b/__tests__/less/__snapshots__/index.test.ts.snap @@ -66,6 +66,7 @@ exports[`less style-loader 2`] = ` -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); color: bisque; + background-image: url(/static/img/logo.png); } /*# sourceMappingURL=index.css.map */ " diff --git a/__tests__/less/index.less b/__tests__/less/index.less index aa6fa8d..2719c97 100644 --- a/__tests__/less/index.less +++ b/__tests__/less/index.less @@ -10,4 +10,5 @@ .index { color: bisque; + background-image: url("/static/img/logo.png"); } diff --git a/src/index.ts b/src/index.ts index a744d1d..1c1937b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -223,6 +223,10 @@ export const styleLoader = (options: StyleLoaderOptions = {}): Plugin => { resolveDir: PATH.dirname(args.path), }; }); + + build.onResolve({ filter: /^\//, namespace: 'css-loader' }, async (args) => { + return { external: true }; + }); }, }; };