From e35478b67a7ffb8a415bc92ae40ece12b2f69025 Mon Sep 17 00:00:00 2001 From: Atanas Angelov Date: Mon, 4 Apr 2022 01:01:20 +0300 Subject: [PATCH] Add TailwindCSS v3 support in hot mode --- .../build/lib/development-mode-plugin.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/resources/build/lib/development-mode-plugin.js b/resources/build/lib/development-mode-plugin.js index 5e268bf..8e1241a 100644 --- a/resources/build/lib/development-mode-plugin.js +++ b/resources/build/lib/development-mode-plugin.js @@ -3,6 +3,9 @@ */ const fs = require('fs'); const path = require('path'); +/* @preset-begin(Tailwind CSS) +const chokidar = require('chokidar'); +@preset-end(Tailwind CSS) */ class DevelopmentModePlugin { constructor({ hot = false }) { @@ -10,6 +13,7 @@ class DevelopmentModePlugin { } apply(compiler) { + // Report development mode options. compiler.hooks.done.tap( 'WP Emerge Development Mode Plugin', (stats) => { @@ -21,6 +25,29 @@ class DevelopmentModePlugin { fs.writeFileSync(filename, JSON.stringify(development)); } ); + + const views = [ + './views/**/*.php', + './*.php', + ]; + + /* @preset-begin(Tailwind CSS) + // Manually invalidate Tailwind's styles when view files change so Tailwind's JIT kicks in. + chokidar + .watch(views) + .on('all', () => { + const watchers = compiler.watchFileSystem.wfs.watcher.fileWatchers.filter((w) => w.path.indexOf('tailwindcss.scss') !== -1); + + for (let i = 0; i < watchers.length; i++) { + watchers[i].directoryWatcher.setFileTime( + watchers[i].path, + new Date().getTime(), + false, + 'change' + ); + } + }); + @preset-end(Tailwind CSS) */ } }