Skip to content

Commit e863c0c

Browse files
committed
Merge pull request #198 from jakemmarsh/disable-debug
Use npm scripts to utilize environment variables, disable debug info in prod
2 parents a412db8 + 1e2295a commit e863c0c

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ A boilerplate using AngularJS, SASS, Gulp, and Browserify that also utilizes [th
1212

1313
1. Clone this repo from `https://github.com/jakemmarsh/angularjs-gulp-browserify-boilerplate.git`
1414
2. Run `npm install` from the root directory
15-
3. Run `gulp dev` (may require installing Gulp globally `npm install gulp -g`)
15+
3. Run `npm run dev`
1616
4. Your browser will automatically be opened and directed to the browser-sync proxy address
17-
5. To prepare assets for production, run the `gulp prod` task (Note: the production task does not fire up the express server, and won't provide you with browser-sync's live reloading. Simply use `gulp dev` during development. More information below)
17+
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)
1818

19-
Now that `gulp 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.
19+
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.
2020

2121
#### Other resources
2222

@@ -109,7 +109,7 @@ Gulp is a "streaming build system", providing a very fast and efficient method f
109109

110110
##### Web Server
111111

112-
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 `gulp` task. 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`.
112+
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`.
113113

114114
##### Scripts
115115

@@ -132,7 +132,7 @@ Just one plugin is necessary for processing our SASS files, and that is `gulp-sa
132132

133133
##### Images
134134

135-
Any images placed within `/app/images` will be automatically copied to the `build/images` directory. If running `gulp prod`, they will also be compressed via imagemin.
135+
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.
136136

137137
##### Views
138138

@@ -142,17 +142,17 @@ Files inside `/app/views/`, on the other hand, go through a slightly more comple
142142

143143
##### Watching files
144144

145-
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 `gulp 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).
145+
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).
146146

147147
##### Production Task
148148

149-
Just as there is the `gulp dev` task for development, there is also a `gulp prod` task 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 `gulp deploy` task 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.
149+
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.
150150

151151
**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.
152152

153153
##### Pre-compressing text assets
154154

155-
When running with `gulp prod`, 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.
155+
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.
156156

157157
##### Testing
158158

@@ -164,7 +164,7 @@ A Gulp tasks also exists for running the test framework (discussed in detail bel
164164

165165
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.
166166

167-
All of the tests can be run at once with the command `gulp test`. However, the tests are broken up into two main categories:
167+
All of the tests can be run at once with the command `npm test`. However, the tests are broken up into two main categories:
168168

169169
##### End-to-End (e2e) Tests
170170

@@ -177,7 +177,7 @@ In this boilerplate, two end-to-end test examples are provided:
177177

178178
More examples can be seen at the above link for Protractor.
179179

180-
All e2e tests are run with `gulp protractor`.
180+
All e2e tests are run with `npm run protractor`.
181181

182182
##### Unit Tests
183183

@@ -190,4 +190,4 @@ An example test is provided for the following types of AngularJS modules:
190190
- `unit/directives/example_spec.js`
191191
- `unit/constants_spec.js`
192192

193-
All unit tests are run with `gulp unit`. When running unit tests, code coverage is simultaneously calculated and output as an HTML file to the `/coverage` directory.
193+
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.

app/js/on_config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
function OnConfig($stateProvider, $locationProvider, $urlRouterProvider) {
1+
function OnConfig($stateProvider, $locationProvider, $urlRouterProvider, $compileProvider) {
22
'ngInject';
33

4+
if (process.env.NODE_ENV === 'production') {
5+
$compileProvider.debugInfoEnabled(false);
6+
}
7+
48
$locationProvider.html5Mode(true);
59

610
$stateProvider

app/js/on_run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function OnRun($rootScope, AppSettings) {
55
$rootScope.$on('$stateChangeSuccess', (event, toState) => {
66
$rootScope.pageTitle = '';
77

8-
if ( toState.title ) {
8+
if (toState.title) {
99
$rootScope.pageTitle += toState.title;
1010
$rootScope.pageTitle += ' \u2014 ';
1111
}

gulp/tasks/browserify.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import uglify from 'gulp-uglify';
1313
import browserSync from 'browser-sync';
1414
import debowerify from 'debowerify';
1515
import ngAnnotate from 'browserify-ngannotate';
16+
import bulkify from 'bulkify';
17+
import envify from 'envify';
1618
import handleErrors from '../util/handleErrors';
1719
import bundleLogger from '../util/bundleLogger';
1820
import config from '../config';
@@ -37,11 +39,12 @@ function buildScript(file) {
3739
}
3840

3941
const transforms = [
40-
{ 'name':babelify, 'options': {}},
41-
{ 'name':debowerify, 'options': {}},
42-
{ 'name':ngAnnotate, 'options': {}},
43-
{ 'name':'brfs', 'options': {}},
44-
{ 'name':'bulkify', 'options': {}}
42+
{ name: babelify, options: {} },
43+
{ name: debowerify, options: {} },
44+
{ name: ngAnnotate, options: {} },
45+
{ name: 'brfs', options: {} },
46+
{ name: bulkify, options: {} },
47+
{ name: envify, options: {} }
4548
];
4649

4750
transforms.forEach(function(transform) {

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularjs-gulp-browserify-boilerplate",
3-
"version": "1.5.10",
3+
"version": "1.6.0",
44
"author": "Jake Marsh <[email protected]>",
55
"description": "Boilerplate using AngularJS, SASS, Gulp, and Browserify while also utilizing best practices.",
66
"repository": {
@@ -40,6 +40,7 @@
4040
"bulkify": "^1.1.1",
4141
"debowerify": "^1.3.1",
4242
"del": "^2.1.0",
43+
"envify": "^3.4.0",
4344
"eslint": "2.2.0",
4445
"express": "^4.13.3",
4546
"gulp": "^3.9.0",
@@ -77,7 +78,12 @@
7778
"watchify": "^3.7.0"
7879
},
7980
"scripts": {
80-
"test": "./node_modules/.bin/gulp test"
81+
"dev": "NODE_ENV=development ./node_modules/.bin/gulp dev",
82+
"build": "NODE_ENV=production ./node_modules/.bin/gulp prod",
83+
"deploy": "NODE_ENV=production ./node_modules/.bin/gulp deploy",
84+
"test": "NODE_ENV=test ./node_modules/.bin/gulp test",
85+
"protractor": "NODE_ENV=test ./node_modules/.bin/gulp protractor",
86+
"unit": "NODE_ENV=test ./node_modules/.bin/gulp unit"
8187
},
8288
"license": "MIT"
8389
}

0 commit comments

Comments
 (0)