Created
September 15, 2015 16:23
-
-
Save xenoterracide/2a9f8f9e2b42c6581fcb to your computer and use it in GitHub Desktop.
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
'use strict'; | |
var gulp = require( 'gulp' ), | |
sourcemaps = require( 'gulp-sourcemaps' ), | |
concat = require( 'gulp-concat' ), | |
watch = require( 'gulp-watch' ), | |
gutil = require( 'gulp-util' ), | |
changed = require( 'gulp-changed' ), | |
cache = require( 'gulp-cached' ), | |
browserSync = require( 'browser-sync' ), | |
browserify = require( 'browserify' ), | |
source = require( 'vinyl-source-stream' ), | |
buffer = require( 'vinyl-buffer' ) | |
; | |
var reload = browserSync.reload; | |
var DEST = "dist"; | |
var libs = [ | |
'angular', | |
'angular-sanitize', | |
'angular-aria', | |
'angular-animate', | |
'angular-material', | |
'angular-translate', | |
'angular-ui-router' | |
]; | |
gulp.task( 'build', [ 'css:vendor', 'js:vendor', 'js:app' ], function() { | |
return gulp.src( 'app/index.html' ) | |
.pipe( gulp.dest( DEST ) ) | |
.pipe( reload( { stream: true } ) ); | |
} ); | |
gulp.task( 'serve', [ 'build' ], function() { | |
browserSync( { | |
server: { | |
baseDir: DEST | |
} | |
} ); | |
gulp.watch( [ '**/*.html', 'css/**/*.*css', 'js/**/*.js' ], { cwd: 'app' }, [ 'build' ] ); | |
} ); | |
gulp.task( 'default', function() { | |
// place code for your default task here | |
} ); | |
gulp.task( 'js:config', function() { | |
var nconf = require( 'nconf' ), | |
rename = require( 'gulp-rename' ), | |
ngConstant = require( 'gulp-ng-constant' ); | |
nconf.use( 'memory' ).argv() | |
.env( { | |
separator: '_', | |
match: /^RPF/ | |
} ) | |
.defaults( {} ); | |
ngConstant( { | |
name: 'rpfCm.constants', | |
constants: nconf.get(), | |
stream: true | |
} ).pipe( rename( "rpfCmConstants.js" ) ) | |
.pipe( gulp.dest( 'app/generated' ) ); | |
} ); | |
gulp.task( 'css:vendor', function() { | |
var materialCss = 'node_modules/angular-material/angular-material.css'; | |
return gulp.src( materialCss ) | |
.pipe( changed( DEST ) ) | |
.pipe( gulp.dest( DEST ) ); | |
} ); | |
gulp.task( 'js:vendor', function() { | |
var b = browserify( { | |
debug: false, | |
cache: {}, | |
packageCache: {} | |
} ); | |
libs.forEach( function( lib ) { | |
b.require( lib ); | |
} ); | |
return b.bundle() | |
.on( 'error', gutil.log ) | |
.pipe( source( 'vendor.js' ) ) | |
.pipe( buffer() ) | |
.pipe( changed( DEST, { hasChanged: changed.compareSha1Digest } ) ) | |
.pipe( gulp.dest( DEST ) ); | |
} ); | |
gulp.task( 'js:app', [ 'js:template-cache' ], function() { | |
var ngAnnotate = require( 'browserify-ngannotate' ); | |
var b = browserify( { | |
basedir: 'app/js', | |
entries: 'app.js', | |
debug: true, | |
paths: [ '../generated' ], | |
transform: [ ngAnnotate ], | |
externalRequireName: libs, | |
bundleExternal: false, | |
cache: {}, | |
packageCache: {} | |
} ); | |
return b.bundle() | |
.on( 'error', gutil.log ) | |
.pipe( source( 'app.js' ) ) | |
.pipe( buffer() ) | |
.pipe( sourcemaps.init( { loadMaps: true } ) ) | |
.pipe( sourcemaps.write( './' ) ) | |
.pipe( gulp.dest( DEST ) ); | |
} ); | |
gulp.task( 'js:template-cache', function() { | |
var ngHtml2Js = require( 'gulp-ng-html2js' ); | |
return gulp.src( 'app/partials/*.html' ) | |
.pipe( ngHtml2Js( { | |
moduleName: 'rpfCm', | |
prefix: 'partials/' | |
} ) ) | |
.pipe( concat( 'partials.js' ) ) | |
.pipe( gulp.dest( 'app/generated' ) ); | |
} ); | |
gulp.task( 'clean', function( cb ) { | |
var del = require( 'del' ); | |
del( [ DEST ], cb ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment