Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3011,7 +3011,7 @@ async function compileLightningCSS(
}
deps.add(dep.url)
if (urlReplacer) {
const replaceUrl = await urlReplacer(dep.url, id)
const replaceUrl = await urlReplacer(dep.url, dep.loc.filePath)
css = css.replace(dep.placeholder, () => replaceUrl)
} else {
css = css.replace(dep.placeholder, () => dep.url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
isBuild,
page,
untilUpdated,
viteTestUrl,
} from '~utils'

// note: tests should retrieve the element at the beginning of test and reuse it
Expand Down Expand Up @@ -71,3 +72,10 @@ test('css with external url', async () => {
const css = await page.$('.external')
expect(await getBg(css)).toMatch('url("https://vitejs.dev/logo.svg")')
})

test('nested css with relative asset', async () => {
const css = await page.$('.nested-css-relative-asset')
expect(await getBg(css)).toMatch(
isBuild ? /base64/ : `${viteTestUrl}/test.avif`,
)
})
1 change: 1 addition & 0 deletions playground/css-lightningcss/imported.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import url('./nested/nested.css');
@import './imported-at-import.css';

.imported {
Expand Down
3 changes: 3 additions & 0 deletions playground/css-lightningcss/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ <h1>Lightning CSS</h1>

<p>External URL</p>
<div class="external"></div>

<p>Assets relative to nested CSS</p>
<div class="nested-css-relative-asset"></div>
</div>

<script type="module" src="./main.js"></script>
3 changes: 3 additions & 0 deletions playground/css-lightningcss/nested/nested.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.nested-css-relative-asset {
background-image: url('../test.avif');
}
Empty file.