-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Sébastien Chopin <[email protected]>
- Loading branch information
Showing
9 changed files
with
1,538 additions
and
2,387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<template> | ||
<div> | ||
<div> | ||
<CallToAction /> | ||
</div> | ||
<div class="max-w-screen-lg p-4 mx-auto space-y-4"> | ||
<div> | ||
<span class="pr-1 font-medium">This is a HMR test, try changing the color:</span> | ||
<span class="text-indigo-500">meow!</span> | ||
</div> | ||
<div> | ||
<span class="text-sm font-semibold text-gray-700">Resolved tailwind config:</span> | ||
<textarea | ||
class="p-4 block text-sm border border-gray-100 rounded shadow w-full h-[32rem] font-mono outline-none" | ||
readonly | ||
:value="JSON.stringify(tailwindConfig, null, 2)" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import tailwindConfig from '#tailwind-config' | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default { | ||
theme: { | ||
extend: { | ||
fontFamily: { | ||
sans: 'Inter, ui-sans-serif, system-ui, -apple-system, Arial, Roboto, sans-serif' | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { isAbsolute, resolve } from 'path' | ||
import { HmrContext, Plugin } from 'vite' | ||
import minimatch from 'minimatch' | ||
|
||
export default function (tailwindConfig, rootDir: string, cssPath: string): Plugin { | ||
const resolvedContent: string[] = tailwindConfig.content.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) { | ||
return | ||
} | ||
|
||
const extraModules = ctx.server.moduleGraph.getModulesByFile(cssPath) | ||
const timestamp = +Date.now() | ||
|
||
for (const mod of extraModules) { | ||
// This will invalidate Vite cache (e.g. next page reload will be fine), but won't help with HMR on its own | ||
ctx.server.moduleGraph.invalidateModule(mod, undefined, timestamp) | ||
} | ||
|
||
// Surely, this is not the best way to fix that, especially given direct `send` call bypassing all Vite logic. | ||
// But just returning extra modules does not cause Vite to send the update, and I didn't find a way to trigger | ||
// that update manually other than sending it directly | ||
|
||
ctx.server.ws.send({ | ||
type: 'update', | ||
updates: Array.from(extraModules).map((mod) => { | ||
return { | ||
type: mod.type === 'js' ? 'js-update' : 'css-update', | ||
path: mod.url, | ||
acceptedPath: mod.url, | ||
timestamp | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
looks like this is wrong