Created
April 9, 2013 11:46
-
-
Save j3lte/5345056 to your computer and use it in GitHub Desktop.
Simple NodeJS observer. I needed a simple observer which would minify my app.js into app.min.js on saving the file. I'm sure this can be done more efficient, I just needed a small script inside my Javascript folder when developing a client-side app for a client of mine. This observer will minify it using packer (https://github.com/dreamerslab/no…
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
| var fs = require("fs"); | |
| var forker = require('child_process'); | |
| var log = console.log; | |
| log('\nRunning under Node.js version ' + process.versions.node + ' on ' + process.arch + | |
| '-type processor, ' + process.platform + ' platform.'); | |
| var fileName = "app.js"; | |
| var fileNameMin = "app.min.js"; | |
| log("Watching: " + fileName); | |
| fs.watch(fileName, { | |
| persistent: true | |
| }, function(event, filename) { | |
| log(event + " event occurred on " + filename); | |
| if (event == "change"){ | |
| log("Packing " + filename + " with packer into " + fileNameMin + ". Just a moment please..."); | |
| forker.exec('packer -b -i '+filename+' -o '+fileNameMin, function(err, outstr){ | |
| if (err){ | |
| log("ERROR"); | |
| } else { | |
| log("SUCCESS"); | |
| } | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment