├── .babelrc
├── .editorconfig
├── .eslintrc
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── app
├── images
│ ├── angular.png
│ ├── browserify.png
│ └── gulp.png
├── index.html
├── js
│ ├── constants.js
│ ├── controllers
│ │ ├── example.js
│ │ └── index.js
│ ├── directives
│ │ ├── example.js
│ │ └── index.js
│ ├── filters
│ │ ├── example.js
│ │ └── index.js
│ ├── main.js
│ ├── on_config.js
│ ├── on_run.js
│ └── services
│ │ ├── example.js
│ │ └── index.js
├── styles
│ ├── _typography.scss
│ ├── _vars.scss
│ └── main.scss
└── views
│ ├── directives
│ └── example.html
│ └── home.html
├── gulp
├── config.js
├── index.js
├── tasks
│ ├── browserSync.js
│ ├── browserify.js
│ ├── clean.js
│ ├── deploy.js
│ ├── development.js
│ ├── eslint.js
│ ├── fonts.js
│ ├── gzip.js
│ ├── images.js
│ ├── production.js
│ ├── protractor.js
│ ├── styles.js
│ ├── test.js
│ ├── unit.js
│ ├── views.js
│ └── watch.js
└── util
│ ├── bundleLogger.js
│ ├── handleErrors.js
│ ├── scriptFilter.js
│ └── testServer.js
├── gulpfile.babel.js
├── package.json
└── test
├── .eslintrc
├── e2e
├── example_spec.js
└── routes_spec.js
├── karma.conf.js
├── protractor.conf.js
└── unit
├── constants_spec.js
├── controllers
└── example_spec.js
├── directives
└── example_spec.js
├── filters
└── example_spec.js
└── services
└── example_spec.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015"]
3 | }
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = space
5 | indent_size = 2
6 | end_of_line = lf
7 | charset = utf-8
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
14 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "parser": "babel-eslint",
3 | "ecmaFeatures": {
4 | "modules": true
5 | },
6 | "env": {
7 | "browser": true,
8 | "node": true,
9 | "es6": true
10 | },
11 | "rules": {
12 | "quotes": [2, "single"],
13 | "eol-last": 0,
14 | "no-debugger": 1,
15 | "no-mixed-requires": 0,
16 | "no-underscore-dangle": 0,
17 | "no-multi-spaces": 0,
18 | "no-trailing-spaces": 0,
19 | "no-extra-boolean-cast": 0,
20 | "no-unused-vars": 2,
21 | "new-cap": 0,
22 | "camelcase": 2
23 | }
24 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
3 | # Logs
4 | logs
5 | *.log
6 |
7 | # Runtime data
8 | pids
9 | *.pid
10 | *.seed
11 |
12 | # Directory for instrumented libs generated by jscoverage/JSCover
13 | lib-cov
14 |
15 | # Coverage directory used by tools like istanbul
16 | coverage
17 |
18 | # Compiled binary addons (http://nodejs.org/api/addons.html)
19 | build/Release
20 |
21 | # Dependency directories
22 | node_modules
23 | bower_components
24 |
25 | # Build files
26 | build
27 | templates.js
28 |
29 | #webstorm
30 | .idea
31 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "4.2"
4 | sudo: false
5 |
6 | script:
7 | - ./node_modules/.bin/gulp eslint
8 | - ./node_modules/.bin/gulp test
9 |
10 | cache:
11 | directories:
12 | - node_modules
13 |
14 | addons:
15 | sauce_connect: true
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Jake Marsh
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | angularjs-gulp-browserify-boilerplate
2 | =====================================
3 | **:exclamation: Warning: This boilerplate is no longer maintained and I would not recommend starting a new project with it.**
4 |
5 | ---
6 |
7 | [](https://travis-ci.org/jakemmarsh/angularjs-gulp-browserify-boilerplate) [](https://david-dm.org/jakemmarsh/angularjs-gulp-browserify-boilerplate) [](https://david-dm.org/jakemmarsh/angularjs-gulp-browserify-boilerplate#info=devDependencies)
8 |
9 | A boilerplate using AngularJS, SASS, Gulp, and Browserify that also utilizes [these best AngularJS practices](https://github.com/toddmotto/angularjs-styleguide) and Gulp best practices from [this resource](https://github.com/greypants/gulp-starter).
10 |
11 | [View contributors](https://github.com/jakemmarsh/angularjs-gulp-browserify-boilerplate/graphs/contributors)
12 |
13 | ---
14 |
15 | ### Getting up and running
16 |
17 | 1. Clone this repo from `https://github.com/jakemmarsh/angularjs-gulp-browserify-boilerplate.git`
18 | 2. Run `npm install` from the root directory
19 | 3. Run `npm run dev`
20 | 4. Your browser will automatically be opened and directed to the browser-sync proxy address
21 | 5. To prepare assets for production, run the `npm run build` script (Note: the production task does not fire up the express server, and won't provide you with browser-sync's live reloading. Simply use `npm run dev` during development. More information below)
22 |
23 | Now that `npm run dev` is running, the server is up as well and serving files from the `/build` directory. Any changes in the `/app` directory will be automatically processed by Gulp and the changes will be injected to any open browsers pointed at the proxy address.
24 |
25 | #### Other resources
26 |
27 | - [Yeoman generator](https://github.com/alferov/generator-angular-gulp-browserify)
28 | - [Cordova-friendly fork](https://github.com/StrikeForceZero/angularjs-cordova-gulp-browserify-boilerplate)
29 |
30 | ---
31 |
32 | This boilerplate uses the latest versions of the following libraries:
33 |
34 | - [AngularJS](http://angularjs.org/)
35 | - [SASS](http://sass-lang.com/)
36 | - [Gulp](http://gulpjs.com/)
37 | - [Browserify](http://browserify.org/)
38 |
39 | Along with many Gulp libraries (these can be seen in either `package.json`, or at the top of each task in `/gulp/tasks/`).
40 |
41 | ---
42 |
43 | ### AngularJS
44 |
45 | AngularJS is a MVW (Model-View-Whatever) Javascript Framework for creating single-page web applications. In this boilerplate, it is used for all the application routing as well as all of the frontend views and logic.
46 |
47 | The AngularJS files are all located within `/app/js`, structured in the following manner:
48 |
49 | ```
50 | /controllers
51 | index.js (the main module on which all controllers will be mounted, loaded in main.js)
52 | example.js
53 | /directives
54 | index.js (the main module on which all directives will be mounted, loaded in main.js)
55 | example.js
56 | /filters
57 | index.js (the main module on which all filters will be mounted, loaded in main.js)
58 | example.js
59 | /services
60 | index.js (the main module on which all services will be mounted, loaded in main.js)
61 | example.js
62 | constants.js (any constant values that you want to make available to Angular)
63 | main.js (the main file read by Browserify, also where the application is defined and bootstrapped)
64 | on_run.js (any functions or logic that need to be executed on app.run)
65 | on_config.js (all route definitions and any logic that need to be executed on app.config)
66 | templates.js (this is created via Gulp by compiling your views, and will not be present beforehand)
67 | ```
68 |
69 | ##### Module organization
70 |
71 | Controllers, services, directives, etc. should all be placed within their respective folders, and will be automatically required and mounted via their respective `index.js` using `bulk-require`. All modules must export an object of the format:
72 |
73 | ```javascript
74 | const ExampleModule = function() {};
75 |
76 | export default {
77 | name: 'ExampleModule',
78 | fn: ExampleModule
79 | };
80 |
81 | ```
82 |
83 | ##### Dependency injection
84 |
85 | Dependency injection is carried out with the `ng-annotate` library. In order to take advantage of this, a simple directive prologue of the format:
86 |
87 | ```js
88 | function MyService($http) {
89 | 'ngInject';
90 | ...
91 | }
92 | ```
93 |
94 | needs to be added at the very beginning of any Angular functions/modules. The Gulp tasks will then take care of adding any dependency injection, requiring you to only specify the dependencies within the function parameters and nothing more.
95 |
96 | ---
97 |
98 | ### SASS
99 |
100 | SASS, standing for 'Syntactically Awesome Style Sheets', is a CSS extension language adding things like extending, variables, and mixins to the language. This boilerplate provides a barebones file structure for your styles, with explicit imports into `app/styles/main.scss`. A Gulp task (discussed later) is provided for compilation and minification of the stylesheets based on this file.
101 |
102 | ---
103 |
104 | ### Browserify
105 |
106 | Browserify is a Javascript file and module loader, allowing you to `require('modules')` in all of your files in the same manner as you would on the backend in a node.js environment. The bundling and compilation is then taken care of by Gulp, discussed below.
107 |
108 | ---
109 |
110 | ### Gulp
111 |
112 | Gulp is a "streaming build system", providing a very fast and efficient method for running your build tasks.
113 |
114 | ##### Web Server
115 |
116 | Gulp is used here to provide a very basic node/Express web server for viewing and testing your application as you build. It serves static files from the `build/` directory, leaving routing up to AngularJS. All Gulp tasks are configured to automatically reload the server upon file changes. The application is served to `localhost:3002` once you run the `npm run dev` script. To take advantage of the fast live reload injection provided by browser-sync, you must load the site at the proxy address (within this boilerplate will by default be `localhost:3000`). To change the settings related to live-reload or browser-sync, you can access the UI at `localhost:3001`.
117 |
118 | ##### Scripts
119 |
120 | A number of build processes are automatically run on all of our Javascript files, run in the following order:
121 |
122 | - **JSHint:** Gulp is currently configured to run a JSHint task before processing any Javascript files. This will show any errors in your code in the console, but will not prevent compilation or minification from occurring.
123 | - **Browserify:** The main build process run on any Javascript files. This processes any of the `require('module')` statements, compiling the files as necessary.
124 | - **Babelify:** This uses [babelJS](https://babeljs.io/) to provide support for ES6+ features.
125 | - **Debowerify:** Parses `require()` statements in your code, mapping them to `bower_components` when necessary. This allows you to use and include bower components just as you would npm modules.
126 | - **ngAnnotate:** This will automatically add the correct dependency injection to any AngularJS files, as mentioned previously.
127 | - **Uglifyify:** This will minify the file created by Browserify and ngAnnotate.
128 |
129 | The resulting file (`main.js`) is placed inside the directory `/build/js/`.
130 |
131 | ##### Styles
132 |
133 | Just one plugin is necessary for processing our SASS files, and that is `gulp-sass`. This will read the `main.scss` file, processing and importing any dependencies and then minifying the result. This file (`main.css`) is placed inside the directory `/build/css/`.
134 |
135 | - **gulp-autoprefixer:** Gulp is currently configured to run autoprefixer after compiling the scss. Autoprefixer will use the data based on current browser popularity and property support to apply prefixes for you. Autoprefixer is recommended by Google and used in Twitter, WordPress, Bootstrap and CodePen.
136 |
137 | ##### Images
138 |
139 | Any images placed within `/app/images` will be automatically copied to the `build/images` directory. If running `npm run build`, they will also be compressed via imagemin.
140 |
141 | ##### Views
142 |
143 | When any changes are made to the `index.html` file, the new file is simply copied to the `/build/` directory without any changes occurring.
144 |
145 | Files inside `/app/views/`, on the other hand, go through a slightly more complex process. The `gulp-angular-templatecache` module is used in order to process all views/partials, creating the `template.js` file briefly mentioned earlier. This file will contain all the views, now in Javascript format inside Angular's `$templateCache` service. This will allow us to include them in our Javascript minification process, as well as avoid extra HTTP requests for our views.
146 |
147 | ##### Watching files
148 |
149 | All of the Gulp processes mentioned above are run automatically when any of the corresponding files in the `/app` directory are changed, and this is thanks to our Gulp watch tasks. Running `npm run dev` will begin watching all of these files, while also serving to `localhost:3002`, and with browser-sync proxy running at `localhost:3000` (by default).
150 |
151 | ##### Production Task
152 |
153 | Just as there is the `npm run dev` command for development, there is also a `npm run build` command for putting your project into a production-ready state. This will run each of the tasks, while also adding the image minification task discussed above. There is also an empty deploy task (run with `npm run deploy`) that is included when running the production task. This deploy task can be fleshed out to automatically push your production-ready site to your hosting setup.
154 |
155 | **Reminder:** When running the production task, gulp will not fire up the express server and serve your index.html. This task is designed to be run before the `deploy` step that may copy the files from `/build` to a production web server.
156 |
157 | ##### Pre-compressing text assets
158 |
159 | When building with `npm run build`, a pre-compressed file is generated in addition to uncompressed file (.html.gz, .js.gz, css.gz). This is done to enable web servers serve compressed content without having to compress it on the fly. Pre-compression is handled by `gzip` task.
160 |
161 | ##### Testing
162 |
163 | A Gulp tasks also exists for running the test framework (discussed in detail below). Running `gulp test` will run any and all tests inside the `/test` directory and show the results (and any errors) in the terminal.
164 |
165 | ---
166 |
167 | ### Testing
168 |
169 | This boilerplate also includes a simple framework for unit and end-to-end (e2e) testing via [Karma](http://karma-runner.github.io/) and [Jasmine](http://jasmine.github.io/). In order to test AngularJS modules, the [angular.mocks](https://docs.angularjs.org/api/ngMock/object/angular.mock) module is used.
170 |
171 | All of the tests can be run at once with the command `npm test`. However, the tests are broken up into two main categories:
172 |
173 | ##### End-to-End (e2e) Tests
174 |
175 | e2e tests, as hinted at by the name, consist of tests that involve multiple modules or require interaction between modules, similar to integration tests. These tests are carried out using the Angular library [Protractor](https://github.com/angular/protractor), which also utilizes Jasmine. The goal is to ensure that the flow of your application is performing as designed from start to finish.
176 |
177 | In this boilerplate, two end-to-end test examples are provided:
178 |
179 | - `routes_spec.js`, which tests the functionality of our AngularJS routing
180 | - `example_spec.js`, which tests the functionality of the example route, controller, and view
181 |
182 | More examples can be seen at the above link for Protractor.
183 |
184 | All e2e tests are run with `npm run protractor`.
185 |
186 | ##### Unit Tests
187 |
188 | Unit tests are used to test a single module (or "unit") at a time in order to ensure that each module performs as intended individually. In AngularJS this could be thought of as a single controller, directive, filter, service, etc. That is how the unit tests are organized in this boilerplate.
189 |
190 | An example test is provided for the following types of AngularJS modules:
191 |
192 | - `unit/controllers/example_spec.js`
193 | - `unit/services/example_spec.js`
194 | - `unit/directives/example_spec.js`
195 | - `unit/constants_spec.js`
196 |
197 | All unit tests are run with `npm run unit`. When running unit tests, code coverage is simultaneously calculated and output as an HTML file to the `/coverage` directory.
198 |
--------------------------------------------------------------------------------
/app/images/angular.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakemmarsh/angularjs-gulp-browserify-boilerplate/5cd63d2edb8f37c59710a7dd7494373c246c9837/app/images/angular.png
--------------------------------------------------------------------------------
/app/images/browserify.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakemmarsh/angularjs-gulp-browserify-boilerplate/5cd63d2edb8f37c59710a7dd7494373c246c9837/app/images/browserify.png
--------------------------------------------------------------------------------
/app/images/gulp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jakemmarsh/angularjs-gulp-browserify-boilerplate/5cd63d2edb8f37c59710a7dd7494373c246c9837/app/images/gulp.png
--------------------------------------------------------------------------------
/app/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |