Skip to content

Commit

Permalink
fix: rebuilding a bundle on file change will work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
gerard2perez committed Oct 30, 2017
1 parent b11fd94 commit 4bb35c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
28 changes: 15 additions & 13 deletions src/support/BundleItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,26 @@ export default class BundleItem {
});
}
}
async build (logger, builder) {
async build (builder, logger) {
try {
this.sources.forEach(f => {
this.watcher.unwatch(f);
});
} catch (Ex) { }
let data = await builder(this.file, this.content.slice(0), configuration.server.env === 'development', false, logger);
let sources = [];
let files = [];
for (const key in data) {
files.push(key);
sources = sources.concat(data[key]);
let data = await builder(this.file, this.content.slice(0), configuration.server.env === 'development', false, logger);
let sources = [];
let files = [];
for (const key in data) {
files.push(key);
sources = sources.concat(data[key]);
}
this.sources = sources;
sources.forEach(f => {
this.watcher.add(f);
});
return files;
} catch (Ex) {
console.log(Ex.stack);
}
this.sources = sources;
sources.forEach(f => {
this.watcher.add(f);
});
return files;
}
valueOf () {
return this.file;
Expand Down
6 changes: 3 additions & 3 deletions src/support/CheckBundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function onChange (bundle, file) {
let filepath = resolve(file);
let newhash = await hasfile(file);
if (newhash !== hashes[filepath]) {
reloadFiles(bundle, await bundle.build());
reloadFiles(bundle, await bundle.build(bundle.kind === '.css' ? buildCSS : buildJS));
hashes[filepath] = newhash;
}
}
Expand Down Expand Up @@ -58,7 +58,7 @@ async function DetectChanges (changed) {
}
allBundles[bundle].isUpdating = true;
if (mustrebuild) {
reloadFiles(allBundles[bundle], await allBundles[bundle].build());
reloadFiles(allBundles[bundle], await allBundles[bundle].build(allBundles[bundle].kind === '.css' ? buildCSS : buildJS));
}
}
for (const bundle in allBundles) {
Expand Down Expand Up @@ -90,7 +90,7 @@ async function checkbundles () {
await mkdir(ProyPath('public', 'js'), null);
for (const bundle of configuration.bundles) {
let b = allBundles[bundle.file] = new BundleItem(bundle.file, bundle.content, true);
await b.build(logger, bundle.kind === '.css' ? buildCSS : buildJS);
await b.build(bundle.kind === '.css' ? buildCSS : buildJS, logger);
b.watch(onChange.bind(null, b));
makehashes(b.sources);
}
Expand Down

0 comments on commit 4bb35c3

Please sign in to comment.