Last active
October 25, 2020 20:44
-
-
Save mdarrik/de1b8a48691d0f862438a6d8b9eb9f0a to your computer and use it in GitHub Desktop.
a naive filewatcher for Toast & TailwindCSS
This file contains hidden or 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
import chokidar from 'chokidar' | |
import {create} from 'browser-sync' | |
import {exec} from 'child_process' | |
//initialize browserSync | |
let browserSync = create(); | |
// function for building the site | |
let build = (callback) => { | |
//just run the npm script directly as a child-process | |
exec("npm run build", (error, stdout, stderr) => { | |
//print any output | |
console.log(error); | |
console.log(stdout); | |
console.log(stderr); | |
//if callback is provided, run it | |
if(callback) { | |
callback(error, stdout, stderr); | |
} | |
} ) | |
} | |
browserSync.init({ | |
server: './public' | |
}) | |
let refreshBrowser = (error, stdout, stderr) => { | |
// if there' sno error, reload the changes | |
if(!error || !stderr) { | |
browserSync.reload() | |
} | |
} | |
// do the initial build | |
build(); | |
// watch for changes on the src directory, the toast config, or the tailwind config. | |
chokidar.watch(['src', 'toast.js', 'tailwind-config/tailwind.config.js']).on('all', () => { | |
build(); | |
refreshBrowser(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment