mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
fix(css): fix lightningcss dep url resolution with custom root (#18125)
This commit is contained in:
parent
70813c7f05
commit
eb08f605dd
@ -3095,7 +3095,10 @@ async function compileLightningCSS(
|
||||
}
|
||||
deps.add(dep.url)
|
||||
if (urlReplacer) {
|
||||
const replaceUrl = await urlReplacer(dep.url, dep.loc.filePath)
|
||||
const replaceUrl = await urlReplacer(
|
||||
dep.url,
|
||||
toAbsolute(dep.loc.filePath),
|
||||
)
|
||||
css = css.replace(dep.placeholder, () => replaceUrl)
|
||||
} else {
|
||||
css = css.replace(dep.placeholder, () => dep.url)
|
||||
|
@ -0,0 +1,9 @@
|
||||
import { expect, test } from 'vitest'
|
||||
import { getBg, isBuild, page, viteTestUrl } from '~utils'
|
||||
|
||||
test('url dependency', async () => {
|
||||
const css = await page.$('.url-dep')
|
||||
expect(await getBg(css)).toMatch(
|
||||
isBuild ? /ok-[-\w]+\.png/ : `${viteTestUrl}/ok.png`,
|
||||
)
|
||||
})
|
14
playground/css-lightningcss-root/package.json
Normal file
14
playground/css-lightningcss-root/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "@vitejs/test-css-lightningcss-root",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"debug": "node --inspect-brk ../../packages/vite/bin/vite",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"lightningcss": "^1.27.0"
|
||||
}
|
||||
}
|
3
playground/css-lightningcss-root/root/index.html
Normal file
3
playground/css-lightningcss-root/root/index.html
Normal file
@ -0,0 +1,3 @@
|
||||
<p>url() dependency</p>
|
||||
<div class="url-dep"></div>
|
||||
<script type="module" src="./main.js"></script>
|
1
playground/css-lightningcss-root/root/main.js
Normal file
1
playground/css-lightningcss-root/root/main.js
Normal file
@ -0,0 +1 @@
|
||||
import './url-dep.css'
|
BIN
playground/css-lightningcss-root/root/ok.png
Normal file
BIN
playground/css-lightningcss-root/root/ok.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
7
playground/css-lightningcss-root/root/url-dep.css
Normal file
7
playground/css-lightningcss-root/root/url-dep.css
Normal file
@ -0,0 +1,7 @@
|
||||
.url-dep {
|
||||
background-image: url('./ok.png');
|
||||
background-size: cover;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border: 1px solid black;
|
||||
}
|
8
playground/css-lightningcss-root/vite.config.js
Normal file
8
playground/css-lightningcss-root/vite.config.js
Normal file
@ -0,0 +1,8 @@
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
export default defineConfig({
|
||||
root: 'root',
|
||||
css: {
|
||||
transformer: 'lightningcss',
|
||||
},
|
||||
})
|
@ -598,6 +598,12 @@ importers:
|
||||
specifier: ^1.27.0
|
||||
version: 1.27.0
|
||||
|
||||
playground/css-lightningcss-root:
|
||||
devDependencies:
|
||||
lightningcss:
|
||||
specifier: ^1.27.0
|
||||
version: 1.27.0
|
||||
|
||||
playground/css-no-codesplit: {}
|
||||
|
||||
playground/css-sourcemap:
|
||||
|
Loading…
Reference in New Issue
Block a user