NOTE: gists do not allow directories, so /
cannot be included in filenames. Instead, -
is used in this project. That is to say public-index.html
should actually be read as public/index.html
relative to the root of the project.
This is a very stripped down seed project for AngularJS-based code that is loaded via the require.js AMD and optimized via r.js
Inspired by:
- https://github.com/tnajdek/angular-requirejs-seed/
- https://github.com/L1fescape/webapp-template
Note that the public/js/MainCtrl.js
file is not necessary for loading angular, but it is helpful to see that a controller can be loaded.
This project is designed to show the basic requirements for require.config
and build.js
(standard name for r.js
build file) in order to get an AngularJS-based project to work during development and after optimization.
build.js
reference tomainConfigFile
is important. Otherwise the shims forangular
will not exist- Using
ng-app
in HTML does not work. Instead, you have to load the Angular module yourself viaangular.bootstrap
The use of public
as the application directory is simply a standard. This could be anything, and in fact another directory is not necessary. The root of the project could contain the entire project directory. It is nice for a project to expose a document root rather than the entire project, though.
dist
is also a standard, but this can be renamed.
In order to run the project, you can use any server you like.
cd public
python -m SimpleHTTPServer
will work, but as long as public
is the document root of the current server, the project will work.
r.js
must be installed. You can install this globally or as a node_modules
module of the actual project. Whatever it takes, you will run
/path/to/r.js -o build.js
This will create the dist
folder that has the same scheme as public
except main.js
is optimized (i.e. has all of the JavaScript code as it is needed). CSS will also be optimized -- blah blah.
At this point, you can run SimpleHTTPServer
or whatever you want while under the dist
directory and it should work identically to public
. It's just a little harder to debug.
Additional components for loading/running the app were omitted for simplicity. You can use whatever you like as long as the end result after r.js
is run is the same.