Simplify bundler a little (#2290)

- Remove a useless abstraction
- Remove a useless write + read
- Only read when generating the bundle
- Use one watcher instead of two
- Use Chokidar to simplify and make for a better experience
This commit is contained in:
Isiah Meadows 2018-11-27 18:02:35 -05:00 committed by GitHub
parent a96caf25c5
commit c33621cd52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 1727 additions and 149 deletions

View file

@ -16,7 +16,7 @@ function parse(file) {
}
var error
function run(input, output) {
module.exports = function (input) {
var modules = {}
var bindings = {}
var declaration = /^\s*(?:var|let|const|function)[\t ]+([\w_$]+)/gm
@ -115,19 +115,7 @@ function run(input, output) {
.replace(versionTag, isFile(packageFile) ? parse(packageFile).version : versionTag) // set version
code = ";(function() {\n" + code + "\n}());"
if (!isFile(output) || code !== read(output)) {
//try {new Function(code); console.log("build completed at " + new Date())} catch (e) {}
error = null
fs.writeFileSync(output, code, "utf8")
}
}
module.exports = function(input, output, options) {
run(input, output)
if (options && options.watch) {
fs.watch(process.cwd(), {recursive: true}, function(file) {
if (typeof file === "string" && path.resolve(output) !== path.resolve(file)) run(input, output)
})
}
//try {new Function(code); console.log("build completed at " + new Date())} catch (e) {}
error = null
return code
}