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(vite-plugin): consider content as object #672

Merged
merged 10 commits into from
May 15, 2023
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"destr": "^1.2.2",
"h3": "^1.6.5",
"iron-webcrypto": "^0.7.0",
"minimatch": "^9.0.0",
"micromatch": "^4.0.5",
"pathe": "^1.1.0",
"postcss": "^8.4.23",
"postcss-custom-properties": "^13.1.5",
Expand All @@ -55,6 +55,7 @@
"@nuxt/module-builder": "^0.3.1",
"@nuxt/test-utils": "^3.4.3",
"@tailwindcss/typography": "^0.5.9",
"@types/micromatch": "^4.0.2",
"changelogen": "^0.5.3",
"codecov": "latest",
"eslint": "latest",
Expand Down
80 changes: 63 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions src/hmr.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { isAbsolute, resolve } from 'path'
import { HmrContext, Plugin } from 'vite'
import { minimatch } from 'minimatch'
import { isAbsolute, resolve } from 'pathe'
import type { Plugin as VitePlugin } from 'vite'
import type { Config } from 'tailwindcss'
import micromatch from 'micromatch'

export default function (tailwindConfig: any = {}, rootDir: string, cssPath: string): Plugin {
const resolvedContent: string[] = (tailwindConfig.content || []).map(f => !isAbsolute(f) ? resolve(rootDir, f) : f)
export default function (tailwindConfig: Partial<Config> = {}, rootDir: string, cssPath: string): VitePlugin {
const resolvedContent = ((Array.isArray(tailwindConfig.content) ? tailwindConfig.content : tailwindConfig.content?.files || []).filter(f => typeof f === 'string') as Array<string>).map(f => !isAbsolute(f) ? resolve(rootDir, f) : f)

return {
name: 'nuxt:tailwindcss',
handleHotUpdate (ctx: HmrContext): void {
if (resolvedContent.findIndex(c => minimatch(ctx.file, c)) === -1) {
handleHotUpdate (ctx): void {
if (resolvedContent.findIndex(c => micromatch.isMatch(ctx.file, c)) === -1) {
return
}

const extraModules = ctx.server.moduleGraph.getModulesByFile(cssPath)
const extraModules = ctx.server.moduleGraph.getModulesByFile(cssPath) || new Set()
const timestamp = +Date.now()

for (const mod of extraModules) {
Expand Down