Skip to content

Commit abaa114

Browse files
WIP
1 parent a8b64f3 commit abaa114

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

integrations/vite/url-rewriting.test.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { binary, css, html, svg, test, ts, txt } from '../utils'
33

44
const SIMPLE_IMAGE = `iVBORw0KGgoAAAANSUhEUgAAADAAAAAlAQAAAAAsYlcCAAAACklEQVR4AWMYBQABAwABRUEDtQAAAABJRU5ErkJggg==`
55

6-
describe.each(['postcss', 'lightningcss'])('%s', (transformer) => {
7-
test(
6+
describe.each(['postcss' /*, 'lightningcss'*/])('%s', (transformer) => {
7+
test.debug(
88
'can rewrite urls in production builds',
99
{
1010
fs: {
@@ -48,25 +48,32 @@ describe.each(['postcss', 'lightningcss'])('%s', (transformer) => {
4848
`,
4949
'src/main.ts': ts``,
5050
'src/app.css': css`
51+
@reference 'tailwindcss';
5152
@import './dir-1/bar.css';
5253
@import './dir-1/dir-2/baz.css';
5354
@import './dir-1/dir-2/vector.css';
5455
`,
5556
'src/dir-1/bar.css': css`
56-
.bar {
57+
.test1 {
5758
background-image: url('../../resources/image.png');
5859
}
5960
`,
6061
'src/dir-1/dir-2/baz.css': css`
61-
.baz {
62+
.test2 {
6263
background-image: url('../../../resources/image.png');
6364
}
6465
`,
6566
'src/dir-1/dir-2/vector.css': css`
66-
.baz {
67+
@import './dir-3/vector.css';
68+
.test3 {
6769
background-image: url('../../../resources/vector.svg');
6870
}
6971
`,
72+
'src/dir-1/dir-2/dir-3/vector.css': css`
73+
.test4 {
74+
background-image: url('./vector-2.svg');
75+
}
76+
`,
7077
'resources/image.png': binary(SIMPLE_IMAGE),
7178
'resources/vector.svg': svg`
7279
<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">
@@ -76,6 +83,14 @@ describe.each(['postcss', 'lightningcss'])('%s', (transformer) => {
7683
<circle cx="200" cy="100" r="80" fill="green" />
7784
</svg>
7885
`,
86+
'src/dir-1/dir-2/dir-3/vector-2.svg': svg`
87+
<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">
88+
<rect width="100%" height="100%" fill="blue" />
89+
<circle cx="200" cy="100" r="80" fill="green" />
90+
<rect width="100%" height="100%" fill="red" />
91+
<circle cx="200" cy="100" r="80" fill="pink" />
92+
</svg>
93+
`,
7994
},
8095
},
8196
async ({ fs, exec, expect }) => {
@@ -87,7 +102,7 @@ describe.each(['postcss', 'lightningcss'])('%s', (transformer) => {
87102
await fs.expectFileToContain(files[0][0], [SIMPLE_IMAGE])
88103

89104
let images = await fs.glob('dist/**/*.svg')
90-
expect(images).toHaveLength(1)
105+
expect(images).toHaveLength(2)
91106

92107
await fs.expectFileToContain(files[0][0], [/\/assets\/vector-.*?\.svg/])
93108
},

packages/@tailwindcss-node/src/compile.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ function createCompileOptions({
4040
async loadModule(id: string, base: string) {
4141
return loadModule(id, base, onDependency, customJsResolver)
4242
},
43-
async loadStylesheet(id: string, base: string) {
44-
let sheet = await loadStylesheet(id, base, onDependency, customCssResolver)
43+
async loadStylesheet(id: string, sheetBase: string) {
44+
let sheet = await loadStylesheet(id, sheetBase, onDependency, customCssResolver)
4545

4646
if (shouldRewriteUrls) {
47+
console.log('rewriteUrls', { root: sheetBase, base: sheet.base, basebase: base })
4748
sheet.content = await rewriteUrls({
4849
css: sheet.content,
4950
root: base,

packages/@tailwindcss-node/src/urls.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export async function rewriteUrls({
6363
relativeUrl = './' + relativeUrl
6464
}
6565

66+
console.log({ url, relativeUrl })
67+
6668
return relativeUrl
6769
}
6870

packages/@tailwindcss-postcss/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
110110
DEBUG && I.start('Create compiler')
111111
let compiler = await compileAst(ast, {
112112
base: inputBasePath,
113+
shouldRewriteUrls: true,
113114
onDependency: (path) => {
114115
context.fullRebuildPaths.push(path)
115116
},

packages/@tailwindcss-vite/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export default function tailwindcss(): Plugin[] {
9797
let generated = await root.generate(src, (file) => this.addWatchFile(file), I)
9898
if (!generated) {
9999
roots.delete(id)
100+
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
100101
return src
101102
}
102103
DEBUG && I.end('[@tailwindcss/vite] Generate CSS (build)')
@@ -105,6 +106,8 @@ export default function tailwindcss(): Plugin[] {
105106
generated = optimizeCss(generated, { minify })
106107
DEBUG && I.end('[@tailwindcss/vite] Optimize CSS')
107108

109+
console.log('yield', generated)
110+
108111
return { code: generated }
109112
},
110113
},

0 commit comments

Comments
 (0)