Requiring vs. Browserifying Angular
developer.telerik.com
developer.telerik.com
And then you lose the main advantage of requirejs over browserify.
People came up with techniques to "lazy load" angular components,but as some point one has to ask,is all that complexity worth the effort?
It was enough to turn me off from RequireJS, permanently.
It was enough to intrigue me about Angular, but be wary about using it due to the amount of time needed to twist your brain into thinking in an Angular way.
In comparison to RequireJS, Browserify just works. No complicated config file with shims. Same module style I'm used to from Node. Hell, I can even concat ascii text files into my packaged codebase with brfs.
The end-result gets ran through RequireJS or Browserify based on your preference, and you don't have to wrap your code.
[1]: https://github.com/ericclemmons/grunt-angular-modularize
example backbone app: https://github.com/ivanistheone/backbone-and-browserify-phon...
You are correct that you should be writing your actual angular code in those separate files. And doesn't it make sense that the export of a controller file is an injectable controller? None of this "dependency injection via a string which gets turned into a reference to real code later"
The browserify transform `bulkify` can also be handy to allow you to require a bunch of files based on a glob.
By concatenating everything into a single file and loading that into the browser, you have to do the math in your head to figure out which file the code in question is in. Also, if you have a huge project, the watchify process really starts to slow down development as you are constantly waiting for it to do the concatenation.
I go with the requirejs/r.js approach. During development, requirejs effectively adds script tags to the specific files into your dom and loads your source code directly. No need for a watchify process. When you have a javascript error, the webconsole shows you exactly what file the issue is in. For deployment into production, r.js does the concat and I just load a single file. This unfortunately makes it harder to debug production, but that's the tradeoff. =(
Neither approach is perfect, but it is the best we have right now. I'd love to see someone come up with something that solves all these problems, is well documented and easy to work with.
https://github.com/substack/node-browserify#external-source-...
With Rails, though, you don't need to worry about any of this. Just define your modules and add controllers/services/directives/whatever to them as needed using as many files as you want, and it just works. No module loading required.
Sorry for my ignorance, but does Node have something similar to Sprockets/The Rails Asset Pipeline?
One might argue that Browserify is that JS bundler for Node. The issue is that using it with Angular seems superfluous because Angular has its own module system that works well when you just concat everything.