Skip to content
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

fix: call createFileOnlyEntry() only for CSS deps, fix #4150 #4267

Merged
merged 12 commits into from
Jul 20, 2021
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
40 changes: 40 additions & 0 deletions packages/playground/tailwind/__test__/tailwind.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { isBuild, editFile, untilUpdated, getColor } from '../../testUtils'

test('should render', async () => {
expect(await page.textContent('#pagetitle')).toBe('|Page title|')
})

if (!isBuild) {
test('regenerate CSS and HMR', async () => {
browserLogs.length = 0
const el = await page.$('#pagetitle')
const el2 = await page.$('#helloroot')

expect(await getColor(el)).toBe('rgb(11, 22, 33)')

editFile('src/views/Page.vue', (code) =>
code.replace('|Page title|', '|Page title updated|')
)
await untilUpdated(() => el.textContent(), '|Page title updated|')

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

browserLogs.length = 0

editFile('src/components/HelloWorld.vue', (code) =>
code.replace('text-gray-800', 'text-[rgb(10,20,30)]')
)

await untilUpdated(() => getColor(el2), 'rgb(10, 20, 30)')

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

browserLogs.length = 0
})
}
3 changes: 3 additions & 0 deletions packages/playground/tailwind/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
14 changes: 14 additions & 0 deletions packages/playground/tailwind/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<link rel="stylesheet" href="./index.css" />
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions packages/playground/tailwind/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "test-tailwind",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"debug": "node --inspect-brk ../../vite/bin/vite",
"serve": "vite preview"
},
"dependencies": {
"autoprefixer": "^10.3.0",
"tailwindcss": "^2.2.4",
"vue": "^3.0.8"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.0.0",
"@vue/compiler-sfc": "^3.0.8",
"vue-router": "^4.0.10"
}
}
7 changes: 7 additions & 0 deletions packages/playground/tailwind/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// postcss.config.js
module.exports = {
plugins: {
tailwindcss: { config: __dirname + '/tailwind.config.js' },
autoprefixer: {}
}
}
Binary file added packages/playground/tailwind/public/favicon.ico
Binary file not shown.
12 changes: 12 additions & 0 deletions packages/playground/tailwind/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div>
<h1>Tailwind app</h1>
{{ foo }}
</div>
<router-view />
</template>

<script setup lang="ts">
import { ref } from 'vue';
const foo = ref(42);
</script>
Binary file added packages/playground/tailwind/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/playground/tailwind/src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div id="helloroot" class="bg-red-400 text-gray-800">HelloWorld - {{ count }}</div>
</template>

<script setup lang="ts">
const count = 1;
</script>
6 changes: 6 additions & 0 deletions packages/playground/tailwind/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
// import '../index.css';
paraboul marked this conversation as resolved.
Show resolved Hide resolved

createApp(App).use(router).mount('#app')
16 changes: 16 additions & 0 deletions packages/playground/tailwind/src/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createWebHistory, createRouter } from 'vue-router'
import Page from './views/Page.vue'

const history = createWebHistory()

const routeur = createRouter({
history: history,
routes: [
{
path: '/',
component: Page
}
]
})

export default routeur
26 changes: 26 additions & 0 deletions packages/playground/tailwind/src/views/Page.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<div>
<h1 id="pagetitle" class="text-[rgb(11,22,33)] text-2xl">|Page title|</h1>
<div @click="val = val+1">{{ val }}</div>
<div class="bg-red-100 inline-block h-24 px-8 mb-8 text-[#888888]">Tailwind style</div>
<HelloWorld />
</div>
</template>

<script lang="ts">

import { defineComponent, ref } from 'vue';
import HelloWorld from '../components/HelloWorld.vue';

export default defineComponent({
components: { HelloWorld },
setup() {
const val = ref(0);

return {
val
}
}
});

</script>
12 changes: 12 additions & 0 deletions packages/playground/tailwind/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
mode: 'jit',
purge: [__dirname + '/src/**/*.vue'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {}
},
variants: {
extend: {}
},
plugins: []
}
15 changes: 15 additions & 0 deletions packages/playground/tailwind/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
resolve: {
alias: {
'/@': __dirname
}
},
plugins: [vue()],
build: {
// to make tests faster
minify: false
}
})
14 changes: 11 additions & 3 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import type Sass from 'sass'
import type Stylus from 'stylus' // eslint-disable-line node/no-extraneous-import
import type Less from 'less'
import { Alias } from 'types/alias'
import type { ModuleNode } from '../server/moduleGraph'

// const debug = createDebugger('vite:css')

Expand Down Expand Up @@ -191,9 +192,16 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
if (deps) {
// record deps in the module graph so edits to @import css can trigger
// main import to hot update
const depModules = new Set(
[...deps].map((file) => moduleGraph.createFileOnlyEntry(file))
)
const depModules = new Set<string | ModuleNode>()
for (const file of deps) {
depModules.add(
cssLangRE.test(file)
? moduleGraph.createFileOnlyEntry(file)
: await moduleGraph.ensureEntryFromUrl(
await fileToUrl(file, config, this)
)
)
}
moduleGraph.updateModuleInfo(
thisModule,
depModules,
Expand Down