ama
ama copied to clipboard
How do you setup Browserify in an AngularJS project?
I'm having a lot of trouble figuring out how to use browserify using AngularJS. I'm not sure of best practices setting it up for a medium sized project, and it seems all the tutorials just load a single file and say "it's as easy as that", but what happens in the other folders and all the files to build out Browserify?
Some of the examples don't seem to work either. Some like below throw an error for me that the module is not a method of angular:
// app.js
var angular = require('angular');
angular
.module('app', []);
Using just require('angular');
with no var angular seems
to work though, but it also says it can't bootstrap my ng-app
since it can't find app, but the file built by browserify is available in the page... so do I need to manually bootstrap Angular?
Then how do I load all my other bundles all in the same file so the module getter will find the other files like something as simple as ./app.config.js
that has some application constants. Do you have to require('angular')
in each then require('./app.config.js')
in app.js? And if it's in a feature or component folder do you use an index.js file in each to require everything then require that in app.js? Adding an index.js file to every folder seems really noisy, but appears to be used a lot. I'm really just lost as to how this works and it's convention regarding AngularJS. I assumed it was "like" using use
in PHP, but that doesn't appear to be true.
I've spent so much time trying to figure this out and am hoping you might have an example project a couple files/folders deep that follows your style guide (which I follow religously) that you could just post as a Gist, or in your blog.
Great work on AngularJS Beginner looking forward to see what you have in AngularJS Master (hopefully demystifying ngModelController's API)
Cheers