Skip to content

Commit ebee509

Browse files
authored
fix(css): watch files imported via @import (#1038)
1 parent 866edc0 commit ebee509

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎packages/css/src/lightningcss.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import path from 'node:path'
12
import { browserslistToTargets } from 'lightningcss'
23
import { expect, test } from 'vitest'
4+
import { globalLogger } from '../../../src/utils/logger.ts'
5+
import { writeFixtures } from '../../../tests/utils.ts'
36
import {
7+
bundleWithLightningCSS,
48
esbuildTargetToLightningCSS,
59
transformWithLightningCSS,
610
} from './lightningcss.ts'
@@ -57,3 +61,19 @@ test('transformWithLightningCSS omits the map by default', async () => {
5761
)
5862
expect(result.map).toBeUndefined()
5963
})
64+
65+
test('bundleWithLightningCSS tracks @import-ed files as dependencies', async (context) => {
66+
const { testDir } = await writeFixtures(context, {
67+
'styles.css': `@import './partial.css';`,
68+
'partial.css': `body { color: red }`,
69+
})
70+
71+
const result = await bundleWithLightningCSS(
72+
path.join(testDir, 'styles.css'),
73+
{
74+
logger: globalLogger,
75+
},
76+
)
77+
78+
expect(result.deps).toContain(path.join(testDir, 'partial.css'))
79+
})

‎packages/css/src/lightningcss.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ export async function bundleWithLightningCSS(
101101
sourceMap: options.sourceMap,
102102
resolver: {
103103
async read(filePath: string) {
104+
if (filePath !== filename) {
105+
deps.push(filePath)
106+
}
104107
let fileCode: string
105108
if (code != null && filePath === filename) {
106109
fileCode = code

0 commit comments

Comments
 (0)