Last active
October 29, 2015 01:37
-
-
Save nicksheffield/de586c2e1d6a55de74fd to your computer and use it in GitHub Desktop.
Angular with gulp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var gulp = require('gulp') // the main guy | |
| var order = require('gulp-order') // reorder files in stream | |
| var uglify = require('gulp-uglify') // minify js | |
| var rename = require('gulp-rename') // rename file | |
| var concat = require('gulp-concat') // merge files together | |
| var addsrc = require('gulp-add-src') // mid-stream gulp.src() | |
| var notify = require('gulp-notify') // OS-level notifications | |
| var plumber = require('gulp-plumber') // handle errors without crashing | |
| var annotate = require('gulp-ng-annotate') // safely minify angular | |
| var templateCache = require('gulp-angular-templatecache') // cache angular template files | |
| var paths = { | |
| views: 'app/views/*.html', | |
| angular: ['app/*.js', 'app/**/*.js'], | |
| output: 'dist' | |
| } | |
| var plumberOpts = { | |
| errorHandler: notify.onError("Error: <%= error.message %>") | |
| } | |
| var tplCacheOpts = { | |
| module: 'app.templates' | |
| } | |
| gulp.task('angular', function() { | |
| var stream = gulp.src(paths.views) // grab all the html views | |
| .pipe(plumber(plumberOpts)) // stop any errors from breaking a watch | |
| .pipe(templateCache('templates.js', tplCacheOpts)) // make a template cache from them | |
| .pipe(addsrc(paths.angular)) // add the rest of the angular app | |
| .pipe(order(['app.js'])) // make sure app.js is first | |
| .on('error', function(){}) // suppress jscs error reporting | |
| .pipe(annotate()) // make angular callbacks minifyable | |
| .pipe(uglify()) // minify the code | |
| .pipe(concat('app.min.js')) // merge them all into the same file | |
| .pipe(gulp.dest(paths.output)) // save it into the dist folder | |
| return stream | |
| }) | |
| gulp.task('watch', ['angular'], function() { | |
| gulp.watch(paths.angular, ['angular']) | |
| }) | |
| gulp.task('default', ['angular']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "gulptest", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "gulpfile.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "keywords": [], | |
| "author": "", | |
| "license": "ISC", | |
| "devDependencies": { | |
| "gulp": "^3.9.0", | |
| "gulp-add-src": "^0.2.0", | |
| "gulp-angular-templatecache": "^1.7.0", | |
| "gulp-concat": "^2.6.0", | |
| "gulp-ng-annotate": "^1.0.0", | |
| "gulp-order": "^1.1.1", | |
| "gulp-plumber": "^1.0.1", | |
| "gulp-rename": "^1.2.2", | |
| "gulp-uglify": "^1.2.0", | |
| "gulp-notify": "^2.2.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment