diff --git a/index.js b/index.js index 151d61f..fab653a 100644 --- a/index.js +++ b/index.js @@ -35,6 +35,7 @@ module.exports = postcss.plugin('prefix', (options) => { } this.formatUrl = (path, includePrefix) => { + const isDataUri = /^["']?data:/i.test(path); includePrefix = typeof includePrefix !== 'undefined' ? includePrefix : true; const sanitizedPath = path.replace(/['"]/g, ''); @@ -43,8 +44,9 @@ module.exports = postcss.plugin('prefix', (options) => { } const prefix = includePrefix ? this.getPrefix(sanitizedPath) : ''; + const formatted = isDataUri ? path : url.resolve(prefix, sanitizedPath); - return `url(${url.resolve(prefix, sanitizedPath)})`; + return `url(${formatted})`; }; return postcss().use(functions({ diff --git a/test/fixtures/url.css b/test/fixtures/url.css index dd6385c..0823051 100644 --- a/test/fixtures/url.css +++ b/test/fixtures/url.css @@ -4,4 +4,8 @@ body { p { background: url('/test2.png'); +} + +span { + background: url('data:image/svg+xml;utf8,'); } \ No newline at end of file diff --git a/test/fixtures/url.out.css b/test/fixtures/url.out.css index f72e8cb..4505ca0 100644 --- a/test/fixtures/url.out.css +++ b/test/fixtures/url.out.css @@ -4,4 +4,8 @@ body { p { background: url(https://img2.example.com/test2.png); +} + +span { + background: url('data:image/svg+xml;utf8,'); } \ No newline at end of file