Skip to content

Commit

Permalink
build: Do not try to copy data url
Browse files Browse the repository at this point in the history
  • Loading branch information
lauriro committed Dec 9, 2024
1 parent 5021ee4 commit a893020
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 20 deletions.
7 changes: 4 additions & 3 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/data/build-cp/a.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.a {
background: url("a.svg");
background: url("a.svg") url('data:x');
}

4 changes: 2 additions & 2 deletions test/data/build-cp/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<html>
<head>
<base href="/">
<link rel="stylesheet" href="a.css">
<style>
<link rel="stylesheet" href="a.css" min="a-{h}.css">
<style min>
.b {
background: url("b.svg");
}
Expand Down
2 changes: 2 additions & 0 deletions test/data/snap/1/a-72b5.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.a{background:url(a.svg) url("data:x")}
.b{background:url(b.svg)}
4 changes: 1 addition & 3 deletions test/data/snap/1/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<!DOCTYPE html><html><head><base href=/ ><link rel=stylesheet href=a.css><style>
.b{background:url(b.svg)}
</style></head><body><img src=c.svg></body></html>
<!DOCTYPE html><html><head><base href=/ ><link rel=stylesheet href=a-72b5.css></head><body><img src=c.svg></body></html>
1 change: 1 addition & 0 deletions test/data/snap/1/ls.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.
./a-72b5.css
./a.css
./a.svg
./b.svg
Expand Down
2 changes: 2 additions & 0 deletions test/data/snap/2/build/a-72b5.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.a{background:url(a.svg) url("data:x")}
.b{background:url(b.svg)}
4 changes: 0 additions & 4 deletions test/data/snap/2/build/a.css

This file was deleted.

1 change: 1 addition & 0 deletions test/data/snap/2/build/a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/data/snap/2/build/b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions test/data/snap/2/build/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<!DOCTYPE html><html><head><base href=/ ><link rel=stylesheet href=a.css><style>
.b{background:url(b.svg)}
</style></head><body><img src=c.svg></body></html>
<!DOCTYPE html><html><head><base href=/ ><link rel=stylesheet href=a-72b5.css></head><body><img src=c.svg></body></html>
4 changes: 1 addition & 3 deletions test/data/snap/2/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<!DOCTYPE html><html><head><base href=/ ><link rel=stylesheet href=a.css><style>
.b{background:url(b.svg)}
</style></head><body><img src=c.svg></body></html>
<!DOCTYPE html><html><head><base href=/ ><link rel=stylesheet href=a-72b5.css></head><body><img src=c.svg></body></html>
4 changes: 3 additions & 1 deletion test/data/snap/2/ls.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a893020

Please sign in to comment.