Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch multiple destinations #199

Closed
chrisjaure opened this issue May 30, 2014 · 20 comments · Fixed by #311
Closed

Watch multiple destinations #199

chrisjaure opened this issue May 30, 2014 · 20 comments · Fixed by #311

Comments

@chrisjaure
Copy link

I'm trying to build bundles with dynamic mappings but it doesn't appear to be working.

For example, instead of specifying src and dest, I'm using a dynamic mapping like this:

files: [
        {
          expand: true,     // Enable dynamic expansion.
          cwd: 'lib/',      // Src matches are relative to this path.
          src: ['**/*.app.js'], // Actual pattern(s) to match.
          dest: 'build/',   // Destination path prefix.
          ext: '.min.js',   // Dest filepaths will have this extension.
          extDot: 'first'   // Extensions in filenames begin after the first dot
        }
]

This allows me to generate multiple bundles matching the src pattern. This used to work in an earlier version. Is it not supported anymore?

@chrisjaure
Copy link
Author

Correction: it does build, but there is no output on the console. Watching, however, does not work. No changes to the files are detected so it never rebuilds the bundles.

@chrisjaure
Copy link
Author

Looks like the issue is that the task is run once for each destination, and since I'm using the keepalive option, only the first destination is ever watched. Changes are detected appropriately for the first but not for the others. Updated the issue title to reflect this.

@chrisjaure chrisjaure changed the title Build dynamic mappings Watch multiple destinations Jun 4, 2014
@duro
Copy link

duro commented Jul 28, 2014

I was able to solve for this using the grunt-concurrent plugin and some JS functions for building paths. I am close to having an example I can show. I will post one when it's ready.

@felipap
Copy link

felipap commented Aug 22, 2014

I'm having the same problem, only the first destination is being watched.

@drinchev
Copy link

+1 I'm having the same problem.

@yang
Copy link

yang commented Oct 11, 2014

+1 I'm also having the same problem. It appears that each file will affect only one of the bundles that they appear in. I think.

@QuentinFchx
Copy link

+1 !

@maiermic
Copy link

I would appreciate a solution, too.

@AdrienGib
Copy link

+1 ...

@tleunen
Copy link
Collaborator

tleunen commented Feb 17, 2015

Hey @chrisjaure and @f03lipe, I'd like to take a look at this.. Do you have a test environment to share so I can start somewhere?

@chrisjaure
Copy link
Author

@tleunen Here's a basic setup: https://gist.github.com/chrisjaure/25af865ffb6561adca22

Run grunt browserify:dist to build it and grunt browserify:watch to watch it. While watching, make a change to and save common.js and check the contents of second.min.js to see that it hasn't been updated.

Thanks for looking into this.

@tragiclifestories
Copy link

@tleunen Did you ever get anywhere with this?

@petersendidit
Copy link

If you use the example in https://github.com/jmreidy/grunt-browserify/tree/master/examples/watch and use the 'browserifyWithWatch' task browserify will correctly watch multiple bundles. Using grunt-contrib-watch as the keepAlive seems to work.

As some have noted the problem is that when you specify keepAlive: true browserify never calls the next function which would allow the next bundle to get updated. I don't see an easy way to fix this as grunt is handling the files and handing the browserify task one file at at time. Browserify never knows that there are multiple bundles. You would have to have some new task that does all the multiple bundle file handling so it knows to keep looping over the bundles.

@tleunen
Copy link
Collaborator

tleunen commented Mar 13, 2015

Sorry I'm quite busy these days.. I'll be more available in 2 weeks and will be able to take a look.

@tleunen
Copy link
Collaborator

tleunen commented Mar 23, 2015

I made a change in my fork. Could you test it a bit before I merge it in the main repo?
https://github.com/tleunen/grunt-browserify/tree/feature/multi-dest
You can use my fork by modifying your package.json file and changing the version of grunt-browserify to git://github.com/tleunen/grunt-browserify.git#feature/multi-dest
The change is really minimal but I want to be sure nothing breaks.

@chrisjaure
Copy link
Author

@tleunen Looks like that did the trick! Thanks a bunch!

Some notes:

  • The process died with a segfault once, but it looked like it was caused by watchify. Haven't been able to reproduce it again.
  • Nitpick: it prints >> Watchifying bundle <name>... every time a change is detected and the bundle is updated, which gets a little noisy.
  • Now that I don't have to use grunt-contrib-watch, processor usage is way down and rebundling is super quick, as expected :)

@tleunen
Copy link
Collaborator

tleunen commented Mar 23, 2015

Before, it was printing >> Watchifying.... I added the bundle name so it's easier to know which one is ready. What do you suggest?
I'd like to keep a comment because it tells the user that the bundle is ready.

@chrisjaure
Copy link
Author

When a file changes, I see:

>> <file> changed, updating bundle.
>> File <bundle> created.
>> Watchifying bundle <bundle>...

Isn't it enough to show just the first two messages since it's implied the bundle is being watchified when the task is first run? But that's fine if you can't differentiate between first creation and subsequent creations. I can deal with a little extra noise :)

@tleunen
Copy link
Collaborator

tleunen commented Mar 24, 2015

I merged the watchifying message with the bundle created message. Is it better? :)
So it's now:

>> <file> changed, updating bundle.
>> <bundle> created. Watchifying...

@chrisjaure
Copy link
Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.