gobblejs / gobble-browserify

Bundle CommonJS modules with gobble and Browserify
4 stars 9 forks source link

When serving using a development server, the files are not properly refreshed #10

Open julienw opened 8 years ago

julienw commented 8 years ago

I use gobble@0.10.2 and gobble-browserify@0.6.1.

Here is my quite simple gobblefile:

'use strict';
var gobble = require('gobble');

module.exports = gobble([
  gobble('src/root'),
  gobble('src/js').transform('babel', {}).transform('browserify', {
    entries: 'wobble.js',
    dest: 'bundle.js'
  })
]);

When I change a dependency (even a direct dependency from the main js file) the bundle.js file is not properly updated automatically, despite gobble outputting:

build invalidated (1 file changed). restarting
gobble: 01-babel done in 1ms
gobble: 02-browserify done in 33ms
gobble: 03-merge done in 2ms
gobble: build completed in 39ms
gobble:

I use ES6 modules transformed by babel, so maybe that could be a reason, but I don't believe so. Looking into the .gobblz directory I can see that Babel properly picks up my changes but not browserify.

julienw commented 8 years ago

I did a simple project adapted from my bigger project here: https://github.com/julienw/wobble/tree/gobble-issue, so you can clone the repository and checkout the gobble-issue branch.

Then you can run npm run serve to run the gobble server, and direct your browser to http://localhost:4567. Then you can modify src/js/grid.js to for example return something else and refresh your browser, you'll see nothing happens.

julienw commented 8 years ago

I think the issue is that in the cache object, the grid.js file id and file are /home/julien/perso/git/woggle/.gobble/01-babel/.cache/grid.js, and inputdir is something like /home/julien/perso/git/woggle/.gobble/01-babel/1 (with the last number that's incrementing with rebuilds). So in the function cacheDependency where we replace inputdir by @, this doesn't work.

Now I don't know why the dep's file and id are in .cache... Should we also try to replace the cache dir ? Do we have this directory path somewhere ?

julienw commented 8 years ago

To me, there are 4 ways to fix this:

  1. Remove the cache mechanism. This is handy but this is broken. And then rewrite it.
  2. Make it work with current this.changes values.
  3. Fix this.changes values in gobble core.
  4. Base the functionality on something else than this.changes, which seems to be an internal non-garanteed API.

I'd suggest to do 1 first and then decide whether to do 2 3 or 4...

julienw commented 8 years ago

I disabled the cache in https://github.com/julienw/gobble-browserify/tree/disable-cache and now it works fine for me. It's likely slower for big projects but I don't understand all this good enough to do better.