Skip to content

Commit

Permalink
fix(vite-plugin): consider content as object (#672)
Browse files Browse the repository at this point in the history
* fix: typeof import default in dts

* chore: using nuxt convention for indexing type

* fix(vite-plugin): consider content as object

* chore: use pathe
  • Loading branch information
ineshbose authored May 15, 2023
1 parent 57d0542 commit 59246cf
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 26 deletions.
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

0 comments on commit 59246cf

Please sign in to comment.