Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Gulp file for building a Chrome Extension
'use strict';
//npm install gulp gulp-minify-css gulp-uglify gulp-clean gulp-cleanhtml gulp-jshint gulp-strip-debug gulp-zip --save-dev
var gulp = require('gulp'),
clean = require('gulp-clean'),
cleanhtml = require('gulp-cleanhtml'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
stripdebug = require('gulp-strip-debug'),
uglify = require('gulp-uglify'),
zip = require('gulp-zip');
//clean build directory
gulp.task('clean', function() {
return gulp.src('build/*', {read: false})
//copy static folders to build directory
gulp.task('copy', function() {
return gulp.src('src/manifest.json')
//copy and compress HTML files
gulp.task('html', function() {
return gulp.src('src/*.html')
//run scripts through JSHint
gulp.task('jshint', function() {
return gulp.src('src/scripts/*.js')
//copy vendor scripts and uglify all other scripts, creating source maps
gulp.task('scripts', ['jshint'], function() {
return gulp.src(['src/scripts/**/*.js', '!src/scripts/vendors/**/*.js'])
.pipe(uglify({outSourceMap: true}))
//minify styles
gulp.task('styles', function() {
// return gulp.src('src/styles/**/*.css')
// .pipe(minifycss({root: 'src/styles', keepSpecialComments: 0}))
// .pipe(gulp.dest('build/styles'));
return gulp.src('src/styles/**')
//build ditributable and sourcemaps after other tasks completed
gulp.task('zip', ['html', 'scripts', 'styles', 'copy'], function() {
var manifest = require('./src/manifest'),
distFileName = + ' v' + manifest.version + '.zip',
mapFileName = + ' v' + manifest.version + '';
//collect all source maps
//build distributable extension
return gulp.src(['build/**', '!build/scripts/**/*.map'])
//run all tasks after build directory has been cleaned
gulp.task('default', ['clean'], function() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment