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: don't transform dynamic requires #6967

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/playground/tailwind-ts/__test__/tailwind-ts.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-ts/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-ts/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>
23 changes: 23 additions & 0 deletions packages/playground/tailwind-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "test-tailwind-ts",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"debug": "node --inspect-brk ../../vite/bin/vite",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.2.25",
"vue-router": "^4.0.0"
},
"devDependencies": {
"@types/node": "^16.11.22",
"@types/tailwindcss": "^3.0.8",
"@vitejs/plugin-vue": "workspace:*",
"autoprefixer": "^10.4.0",
"tailwindcss": "^2.2.19",
"ts-node": "^10.4.0"
}
}
7 changes: 7 additions & 0 deletions packages/playground/tailwind-ts/postcss.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import tailwind from 'tailwindcss'
import autoprefixer from 'autoprefixer'
import tailwindConfig from './tailwind.config'

export default {
plugins: [tailwind(tailwindConfig), autoprefixer()]
}
Binary file not shown.
12 changes: 12 additions & 0 deletions packages/playground/tailwind-ts/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div>
<h1 class="text-black">Tailwind app</h1>
{{ foo }}
</div>
<router-view />
</template>

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

<script setup lang="ts">
const count = 1
</script>
5 changes: 5 additions & 0 deletions packages/playground/tailwind-ts/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

createApp(App).use(router).mount('#app')
16 changes: 16 additions & 0 deletions packages/playground/tailwind-ts/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-ts/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>
15 changes: 15 additions & 0 deletions packages/playground/tailwind-ts/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// eslint-disable-next-line node/no-missing-import
import type { TailwindConfig } from 'tailwindcss/tailwind-config'

export default <TailwindConfig>{
mode: 'jit',
purge: [__dirname + '/src/**/*.vue'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {}
},
variants: {
extend: {}
},
plugins: []
}
20 changes: 20 additions & 0 deletions packages/playground/tailwind-ts/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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
},
server: {
// This option caused issues with HMR,
// although it should not affect the build
origin: 'http://localhost:8080/'
}
})
3 changes: 2 additions & 1 deletion packages/vite/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ const createNodeConfig = (isProduction) => {
extensions: ['.js'],
// Optional peer deps of ws. Native deps that are mostly for performance.
// Since ws is not that perf critical for us, just ignore these deps.
ignore: ['bufferutil', 'utf-8-validate']
ignore: ['bufferutil', 'utf-8-validate'],
ignoreDynamicRequires: true
}),
json(),
isProduction && licensePlugin()
Expand Down