Skip to content

Commit

Permalink
Only transform using Vite css plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisBraun committed Mar 22, 2024
1 parent 99f97b1 commit 23351b5
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions packages/@tailwindcss-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function tailwindcss(): Plugin[] {
// In build mode, we store file contents to use them in renderChunk.
let cssModules: Record<string, string> = {}
let minify = false
let plugins: readonly Plugin[] = []
let cssPlugins: readonly Plugin[] = []

// Trigger update to all css modules
function updateCssModules() {
Expand Down Expand Up @@ -78,16 +78,7 @@ export default function tailwindcss(): Plugin[] {
},
}

for (let plugin of plugins) {
if (
// Skip our own plugins
plugin.name.startsWith('@tailwindcss/') ||
// Skip vite:import-analysis and vite:build-import-analysis because they try
// to process CSS as JS and fail.
plugin.name.includes('import-analysis')
)
continue

for (let plugin of cssPlugins) {
if (!plugin.transform) continue
const transformHandler =
'handler' in plugin.transform! ? plugin.transform.handler : plugin.transform!
Expand Down Expand Up @@ -120,7 +111,9 @@ export default function tailwindcss(): Plugin[] {

async configResolved(config) {
minify = config.build.cssMinify !== false
plugins = config.plugins
cssPlugins = config.plugins.filter((plugin) =>
['vite:css', 'vite:css-post'].includes(plugin.name),
)
},

// Scan index.html for candidates
Expand Down

0 comments on commit 23351b5

Please sign in to comment.