From a8930200bebec5e3a3d8c8687b79499b206d32d7 Mon Sep 17 00:00:00 2001 From: Lauri Rooden Date: Mon, 9 Dec 2024 11:10:54 +0200 Subject: [PATCH] build: Do not try to copy data url --- lib/build.js | 7 ++++--- test/data/build-cp/a.css | 2 +- test/data/build-cp/dev.html | 4 ++-- test/data/snap/1/a-72b5.css | 2 ++ test/data/snap/1/index.html | 4 +--- test/data/snap/1/ls.snap | 1 + test/data/snap/2/build/a-72b5.css | 2 ++ test/data/snap/2/build/a.css | 4 ---- test/data/snap/2/build/a.svg | 1 + test/data/snap/2/build/b.svg | 1 + test/data/snap/2/build/index.html | 4 +--- test/data/snap/2/index.html | 4 +--- test/data/snap/2/ls.snap | 4 +++- 13 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 test/data/snap/1/a-72b5.css create mode 100644 test/data/snap/2/build/a-72b5.css delete mode 100644 test/data/snap/2/build/a.css create mode 100644 test/data/snap/2/build/a.svg create mode 100644 test/data/snap/2/build/b.svg diff --git a/lib/build.js b/lib/build.js index d7946d3..dff5726 100644 --- a/lib/build.js +++ b/lib/build.js @@ -381,13 +381,14 @@ function view2js(content) { function cssImport(str, attrs) { var match, out , lastIndex = 0 - , re = /@import\s+url\((['"]?)(?!data:)(.+?)\1\);*/ig + , re = /@import\s+url\((['"]?)(.+?)\1\);*/ig , inDir = path.resolve(attrs.inDir || "", attrs.inFile || "").replace(/[^\/]+$/, "") , outDir = path.resolve(attrs.outDir || "", attrs.outFile || "inline").replace(/[^\/]+$/, "") + , noCpRe = /^(https?|data):/ if (inDir !== outDir) { - str = str.replace(/\/\*(?!!)[^]*?\*\/|url\((['"]?)(?!data:)(.+?)\1\)/ig, function(_, q, name) { - if (name && !httpRe.test(name)) { + str = str.replace(/\/\*(?!!)[^]*?\*\/|url\((['"]?)(.+?)\1\)/ig, function(_, q, name) { + if (name && !noCpRe.test(name)) { try { cli.cp(inDir + name, path.join(outDir, name)) } catch (e) { diff --git a/test/data/build-cp/a.css b/test/data/build-cp/a.css index 767b02e..4ede8b0 100644 --- a/test/data/build-cp/a.css +++ b/test/data/build-cp/a.css @@ -1,4 +1,4 @@ .a { - background: url("a.svg"); + background: url("a.svg") url('data:x'); } diff --git a/test/data/build-cp/dev.html b/test/data/build-cp/dev.html index 57901db..653f435 100644 --- a/test/data/build-cp/dev.html +++ b/test/data/build-cp/dev.html @@ -3,8 +3,8 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/test/data/snap/1/ls.snap b/test/data/snap/1/ls.snap index 42b7a2f..709691a 100644 --- a/test/data/snap/1/ls.snap +++ b/test/data/snap/1/ls.snap @@ -1,4 +1,5 @@ . +./a-72b5.css ./a.css ./a.svg ./b.svg diff --git a/test/data/snap/2/build/a-72b5.css b/test/data/snap/2/build/a-72b5.css new file mode 100644 index 0000000..72b54df --- /dev/null +++ b/test/data/snap/2/build/a-72b5.css @@ -0,0 +1,2 @@ +.a{background:url(a.svg) url("data:x")} +.b{background:url(b.svg)} diff --git a/test/data/snap/2/build/a.css b/test/data/snap/2/build/a.css deleted file mode 100644 index 767b02e..0000000 --- a/test/data/snap/2/build/a.css +++ /dev/null @@ -1,4 +0,0 @@ - .a { - background: url("a.svg"); - } - diff --git a/test/data/snap/2/build/a.svg b/test/data/snap/2/build/a.svg new file mode 100644 index 0000000..37b9dfd --- /dev/null +++ b/test/data/snap/2/build/a.svg @@ -0,0 +1 @@ + diff --git a/test/data/snap/2/build/b.svg b/test/data/snap/2/build/b.svg new file mode 100644 index 0000000..f78c062 --- /dev/null +++ b/test/data/snap/2/build/b.svg @@ -0,0 +1 @@ + diff --git a/test/data/snap/2/build/index.html b/test/data/snap/2/build/index.html index 095053d..d349420 100644 --- a/test/data/snap/2/build/index.html +++ b/test/data/snap/2/build/index.html @@ -1,3 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test/data/snap/2/index.html b/test/data/snap/2/index.html index 095053d..d349420 100644 --- a/test/data/snap/2/index.html +++ b/test/data/snap/2/index.html @@ -1,3 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test/data/snap/2/ls.snap b/test/data/snap/2/ls.snap index 204b794..7944d0e 100644 --- a/test/data/snap/2/ls.snap +++ b/test/data/snap/2/ls.snap @@ -3,7 +3,9 @@ ./a.svg ./b.svg ./build -./build/a.css +./build/a-72b5.css +./build/a.svg +./build/b.svg ./build/c.svg ./build/index.html ./c.svg