-
-
Save TechNinjaWeb/de0adb5a1c0d4873ba56073a30b1e038 to your computer and use it in GitHub Desktop.
Gulp + Watchify + Debowerify + Uglify
This file contains 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
///////////////////////////////////////////////////////////////////////////// | |
///////////////////////////////////////////////////////////////////////////// | |
// Browserify Shims | |
///////////////////////////////////////////////////////////////////////////// | |
///////////////////////////////////////////////////////////////////////////// | |
// var paths = require('./paths'); // Require Your Paths.JS file | |
module.exports = { | |
angular: { | |
path: paths.node + 'angular/angular.js', | |
exports: 'angular', | |
depends: ['jquery'] | |
}, | |
'angular-route': { | |
path: paths.node + 'angular-ui-router/release/angular-ui-router.js', | |
exports: 'ui.router', | |
depends: ['angular'] | |
}, | |
'angular-resource': { | |
path: paths.node + 'angular-resource/release/angular-resource.js', | |
exports: 'ngResource', | |
depends: ['angular'] | |
}, | |
jquery: { | |
path: paths.node + 'jquery/dist/jquery.js', | |
exports: ['jQuery', '$'] | |
}, | |
toastr: { | |
path: paths.node + 'toastr/toastr.js', | |
exports: 'toastr' | |
} | |
} |
This file contains 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
///////////////////////////////////////////////////////////////////////////// | |
///////////////////////////////////////////////////////////////////////////// | |
// Gulp Task Registry | |
//// Load up common taks and dependencies | |
//// for the applications workspace | |
///////////////////////////////////////////////////////////////////////////// | |
///////////////////////////////////////////////////////////////////////////// | |
///////////////////////////////////////////////////////////////////////////// | |
// Required Vars | |
///////////////////////////////////////////////////////////////////////////// | |
var gulp = require('gulp'), | |
paths = require('./gulp/paths.js'), | |
uglify = require('gulp-uglify'), | |
plumber = require('gulp-plumber'), | |
rename = require('gulp-rename'), | |
compass = require('gulp-compass'), | |
browserSync = require('browser-sync'), | |
reload = browserSync.reload, | |
del = require('del'), | |
imagemin = require('gulp-imagemin'), | |
browserify = require('browserify') | |
gulpify = require('gulp-browserify'), | |
shim = require('browserify-shim'), | |
custom_shims = require('./gulp/browserify.shim.js'); | |
///////////////////////////////////////////////////////////////////////////// | |
// Task: Clean - Delete dist and build to allow for nice, clean files! | |
///////////////////////////////////////////////////////////////////////////// | |
gulp.task('clean', function(callback) { | |
return del(['build', 'dist'], callback); | |
}); | |
///////////////////////////////////////////////////////////////////////////// | |
// Task: Scripts | |
///////////////////////////////////////////////////////////////////////////// | |
gulp.task('scripts', function(){ | |
gulp.src([paths.js + '/*.js', '!' + paths.js + '/*.min.js']) | |
.pipe(gulpify({ | |
insertGlobals: true, | |
debug: !gulp.env.production, | |
transform: ['debowerify'], | |
})) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(uglify()) | |
.pipe(gulp.dest(paths.build)) | |
.pipe(reload({stream:true})) | |
}); | |
///////////////////////////////////////////////////////////////////////////// | |
// Task: Watch - Check for changes in files and run additional tasks | |
///////////////////////////////////////////////////////////////////////////// | |
gulp.task('watch', function(){ | |
gulp.watch(paths.js + '/**/*.js', ['scripts']), | |
gulp.watch(paths.scss + '/**/*.scss', ['compass']), | |
gulp.watch(paths.html + '/**/*.html', ['html']); | |
gulp.watch(paths.src + '/index.html', ['html']); | |
}); | |
///////////////////////////////////////////////////////////////////////////// | |
// Task: Styles Compiler | |
///////////////////////////////////////////////////////////////////////////// | |
gulp.task('compass', function(){ | |
gulp.src('src/scss/style.scss') | |
.pipe(plumber()) | |
.pipe(compass({ | |
config_file: './config.rb', | |
css: paths.css, | |
sass: paths.scss, | |
require: ['susy'] | |
})) | |
.pipe(gulp.dest(paths.build)) | |
.pipe(reload({stream:true})) | |
}) | |
///////////////////////////////////////////////////////////////////////////// | |
// Task: Default | |
///////////////////////////////////////////////////////////////////////////// | |
gulp.task('default', ['scripts', 'compass', 'sync', 'watch', 'html'], function(){ | |
console.log("Watching Files..."); | |
}) | |
///////////////////////////////////////////////////////////////////////////// | |
// Task: HTML | |
///////////////////////////////////////////////////////////////////////////// | |
// gulp.task('html', ['html:vulcanize', 'html:ugly'], function(){ | |
// gulp.src([paths.html + '/**/*.html', "./src/index.html"]) | |
// .pipe(gulp.dest(paths.build)) | |
// .pipe(reload({stream:true})) | |
// }); | |
gulp.task('html', function(){ | |
gulp.src([paths.html + '/**/*.html', "./src/index.html"]) | |
.pipe(gulp.dest(paths.build)) | |
.pipe(reload({stream:true})) | |
}); | |
///////////////////////////////////////////////////////////////////////////// | |
// Task: HTML: Vulcanize - Concat all html files into one | |
///////////////////////////////////////////////////////////////////////////// | |
gulp.task('html:vulcanize', function() { | |
return gulp.src(paths.html) | |
.pipe(vulcanize({ | |
abspath: '', | |
excludes: [], | |
stripExcludes: false | |
})) | |
.pipe(gulp.dest(paths.build)); | |
}); | |
///////////////////////////////////////////////////////////////////////////// | |
// Task: HTML: Uglify - Destroy human readability | |
///////////////////////////////////////////////////////////////////////////// | |
gulp.task('html:ugly', ['clean'], function() { | |
// Minify and copy all JavaScript (except vendor scripts) | |
// with sourcemaps all the way down | |
return gulp.src(paths.html) | |
// .pipe(sourcemaps.init()) | |
// .pipe(uglify()) | |
.pipe(concat('bundle.html')) | |
// .pipe(sourcemaps.write()) | |
.pipe(gulp.dest(paths.build)); | |
}); | |
///////////////////////////////////////////////////////////////////////////// | |
// Task: Images | |
///////////////////////////////////////////////////////////////////////////// | |
gulp.task('images', ['clean'], function() { | |
return gulp.src(paths.images) | |
// Pass in options to the task | |
.pipe(imagemin({ | |
optimizationLevel: 5 | |
})) | |
.pipe(gulp.dest('build/assets')); | |
}); | |
///////////////////////////////////////////////////////////////////////////// | |
// Task: Browser Sync - Detects html js css save changes and reloads browsers | |
///////////////////////////////////////////////////////////////////////////// | |
gulp.task('sync', function(){ | |
browserSync({ | |
server: { | |
baseDir: paths.build | |
}, | |
port: 8080, | |
notify: false, // Disable the on-page notice BrowserSync is running. | |
logConnections: true, // Log all devices that are connected., | |
shim: custom_shims | |
}) | |
}); |
This file contains 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
///////////////////////////////////////////////////////////////////////////// | |
///////////////////////////////////////////////////////////////////////////// | |
// Common directory tree | |
///////////////////////////////////////////////////////////////////////////// | |
///////////////////////////////////////////////////////////////////////////// | |
module.exports = { | |
build: './build', | |
entry: './src/index.js', | |
css: './src/css', | |
scss: './src/sass', | |
js: './src/js', | |
html: './src/html', | |
public: './www', | |
bower: './bower_components', | |
node: './node_modules', | |
src: './src' | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment