Skip to content

Commit

Permalink
Add TailwindCSS v3 support in hot mode
Browse files Browse the repository at this point in the history
  • Loading branch information
atanas-dev committed Apr 3, 2022
1 parent 5f7abbb commit e35478b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions resources/build/lib/development-mode-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
*/
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 }) {
this.hot = hot;
}

apply(compiler) {
// Report development mode options.
compiler.hooks.done.tap(
'WP Emerge Development Mode Plugin',
(stats) => {
Expand All @@ -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) */
}
}

Expand Down

0 comments on commit e35478b

Please sign in to comment.