-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve build responsiveness (#2992)
- Loading branch information
1 parent
8353ac2
commit 8048c9f
Showing
4 changed files
with
55 additions
and
7 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 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,36 @@ | ||
const chokidar = require("chokidar"); | ||
const commandLineArgs = require("command-line-args"); | ||
const { exec } = require("child_process"); | ||
|
||
const options = commandLineArgs([ | ||
{ name: "srcFiles", type: String }, | ||
]); | ||
|
||
const runPostcss = path => { | ||
let command = `postcss ${path} --config config/postcss.components --base src --dir dist/css/`; | ||
console.log(`Executing: ${command}`); | ||
exec(command, (err, stdout, stderr) => { | ||
if (err) { | ||
console.log(`Could not run postcss for ${path}. Error: ${err}`); | ||
} | ||
}); | ||
|
||
command = `${command} -w`; | ||
console.log(`Executing: ${command}`); | ||
exec(command, (err, stdout, stderr) => { | ||
if (err) { | ||
console.log(`Could not run postcss in watch mode for ${path}. Error: ${err}`); | ||
} | ||
}); | ||
}; | ||
|
||
let ready = false; // Do nothing until the ready event has been fired (we don't want to recompile all files initially) | ||
const watcher = chokidar.watch(options.srcFiles); | ||
watcher.on("ready", () => { | ||
ready = true; // Initial scan is over -> waiting for new files | ||
}); | ||
watcher.on("add", path => { | ||
if (ready) { | ||
runPostcss(path); | ||
} | ||
}); |
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