diff --git a/lib/plugins/postcss-baseurl.js b/lib/plugins/postcss-baseurl.js
index 94a095e..aded6bc 100644
--- a/lib/plugins/postcss-baseurl.js
+++ b/lib/plugins/postcss-baseurl.js
@@ -1,3 +1,4 @@
+import path from 'pathe'
import isUrl from 'is-url-superb'
const urlPattern = /(url\(["']?)(.*?)(["']?\))/g
@@ -13,7 +14,11 @@ export default function postcssBaseurl(options = {}) {
rule.walkDecls(decl => {
const { value } = decl
decl.value = value.replace(urlPattern, ($0, $1, $2, $3) => {
- return isUrl($2) ? $1 + $2 + $3 : $1 + base + $2 + $3
+ return isUrl($2)
+ ? $1 + $2 + $3
+ : isUrl(base)
+ ? $1 + base + $2 + $3
+ : $1 + path.join(base, $2) + $3
})
})
}
@@ -23,7 +28,11 @@ export default function postcssBaseurl(options = {}) {
rule.walkDecls(decl => {
const { value } = decl
decl.value = value.replace(urlPattern, ($0, $1, $2, $3) => {
- return isUrl($2) ? $1 + $2 + $3 : $1 + base + $2 + $3
+ return isUrl($2)
+ ? $1 + $2 + $3
+ : isUrl(base)
+ ? $1 + base + $2 + $3
+ : $1 + path.join(base, $2) + $3
})
})
})
diff --git a/test/expected/bg-paths.html b/test/expected/bg-paths.html
new file mode 100644
index 0000000..bb7b204
--- /dev/null
+++ b/test/expected/bg-paths.html
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+ Header |
+
+
+ Cell |
+
+
+
diff --git a/test/fixtures/bg-paths.html b/test/fixtures/bg-paths.html
new file mode 100644
index 0000000..b723034
--- /dev/null
+++ b/test/fixtures/bg-paths.html
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+ Header |
+
+
+ Cell |
+
+
+
diff --git a/test/test.js b/test/test.js
index 2699877..8cab471 100644
--- a/test/test.js
+++ b/test/test.js
@@ -126,3 +126,11 @@ test('joins relative paths', t => {
},
})
})
+
+test('joins bg url paths', t => {
+ return process(t, 'bg-paths', {
+ url: 'relative',
+ styleTag: true,
+ inlineCss: true,
+ })
+})