Skip to content

Commit

Permalink
fix: normalize postcss dependency messages (#6959)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibbng committed Feb 17, 2022
1 parent 08cf4e1 commit 3f3f473
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
22 changes: 21 additions & 1 deletion packages/playground/tailwind/__test__/tailwind.spec.ts
Expand Up @@ -5,7 +5,7 @@ test('should render', async () => {
})

if (!isBuild) {
test('regenerate CSS and HMR', async () => {
test('regenerate CSS and HMR (glob pattern)', async () => {
browserLogs.length = 0
const el = await page.$('#pagetitle')
const el2 = await page.$('#helloroot')
Expand Down Expand Up @@ -37,4 +37,24 @@ if (!isBuild) {

browserLogs.length = 0
})

test('regenerate CSS and HMR (relative path)', async () => {
browserLogs.length = 0
const el = await page.$('h1')

expect(await getColor(el)).toBe('black')

editFile('src/App.vue', (code) =>
code.replace('text-black', 'text-[rgb(11,22,33)]')
)

await untilUpdated(() => getColor(el), 'rgb(11, 22, 33)')

expect(browserLogs).toMatchObject([
'[vite] css hot updated: /index.css',
'[vite] hot updated: /src/App.vue'
])

browserLogs.length = 0
})
}
2 changes: 1 addition & 1 deletion packages/playground/tailwind/src/App.vue
@@ -1,6 +1,6 @@
<template>
<div>
<h1>Tailwind app</h1>
<h1 class="text-black">Tailwind app</h1>
{{ foo }}
</div>
<router-view />
Expand Down
7 changes: 6 additions & 1 deletion packages/playground/tailwind/tailwind.config.js
@@ -1,6 +1,11 @@
module.exports = {
mode: 'jit',
purge: [__dirname + '/src/**/*.vue'],
purge: [
// Before editing this section, make sure no paths are matching with `/src/App.vue`
// Look https://github.com/vitejs/vite/pull/6959 for more details
__dirname + '/src/{components,views}/**/*.vue',
__dirname + '/src/App.vue'
],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Expand Up @@ -759,7 +759,7 @@ async function compileCSS(
// record CSS dependencies from @imports
for (const message of postcssResult.messages) {
if (message.type === 'dependency') {
deps.add(message.file as string)
deps.add(normalizePath(message.file as string))
} else if (message.type === 'dir-dependency') {
// https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#3-dependencies
const { dir, glob: globPattern = '**' } = message
Expand Down

0 comments on commit 3f3f473

Please sign in to comment.