Skip to content

Vite: Don't rebase urls that appear to be aliases #16078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Refactor gradient implementation to work around [prettier/prettier#17058](https://github.com/prettier/prettier/issues/17058) ([#16072](https://github.com/tailwindlabs/tailwindcss/pull/16072))
- Vite: Ensure hot-reloading works with SolidStart setups ([#16052](https://github.com/tailwindlabs/tailwindcss/pull/16052))
- Vite: Fix a crash when starting the development server in SolidStart setups ([#16052](https://github.com/tailwindlabs/tailwindcss/pull/16052))
- Vite: Don't rebase urls that appear to be aliases ([#16078](https://github.com/tailwindlabs/tailwindcss/pull/16078))
- Prevent camelCasing CSS custom properties added by JavaScript plugins ([#16103](https://github.com/tailwindlabs/tailwindcss/pull/16103))

## [4.0.1] - 2025-01-29
Expand Down
26 changes: 26 additions & 0 deletions packages/@tailwindcss-node/src/urls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ test('URLs can be rewritten', async () => {
background: url('/image.jpg');
background: url("/image.jpg");

/* Potentially Vite-aliased URLs: ignored */
background: url(~/image.jpg);
background: url(~/foo/image.jpg);
background: url('~/image.jpg');
background: url("~/image.jpg");
background: url(#/image.jpg);
background: url(#/foo/image.jpg);
background: url('#/image.jpg');
background: url("#/image.jpg");
background: url(@/image.jpg);
background: url(@/foo/image.jpg);
background: url('@/image.jpg');
background: url("@/image.jpg");

/* External URL: ignored */
background: url(http://example.com/image.jpg);
background: url('http://example.com/image.jpg');
Expand Down Expand Up @@ -109,6 +123,18 @@ test('URLs can be rewritten', async () => {
background: url(/foo/image.jpg);
background: url('/image.jpg');
background: url("/image.jpg");
background: url(~/image.jpg);
background: url(~/foo/image.jpg);
background: url('~/image.jpg');
background: url("~/image.jpg");
background: url(#/image.jpg);
background: url(#/foo/image.jpg);
background: url('#/image.jpg');
background: url("#/image.jpg");
background: url(@/image.jpg);
background: url(@/foo/image.jpg);
background: url('@/image.jpg');
background: url("@/image.jpg");
background: url(http://example.com/image.jpg);
background: url('http://example.com/image.jpg');
background: url("http://example.com/image.jpg");
Expand Down
7 changes: 5 additions & 2 deletions packages/@tailwindcss-node/src/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ async function doUrlReplace(
return `${funcName}(${wrap}${newUrl}${wrap})`
}

function skipUrlReplacer(rawUrl: string) {
function skipUrlReplacer(rawUrl: string, aliases?: string[]) {
return (
isExternalUrl(rawUrl) || isDataUrl(rawUrl) || rawUrl[0] === '#' || functionCallRE.test(rawUrl)
isExternalUrl(rawUrl) ||
isDataUrl(rawUrl) ||
!rawUrl[0].match(/[\.a-zA-Z0-9_]/) ||
functionCallRE.test(rawUrl)
)
}

Expand Down