Created
November 26, 2015 14:01
-
-
Save raphw/6a66456d63311ccb65c4 to your computer and use it in GitHub Desktop.
Simple Gulp script
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
{ | |
"name": "app", | |
"version": "0.0.0", | |
"authors": [ | |
"foo <foo@bar.qux>" | |
], | |
"license": "MIT", | |
"private": true, | |
"ignore": [ | |
"**/.*", | |
"node_modules", | |
"bower_components", | |
"test", | |
"tests" | |
], | |
"devDependencies": { | |
"foundation": "~5.5.1", | |
"foundation-icon-fonts": "*" | |
} | |
} |
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
'use strict'; | |
var gulp = require('gulp'); | |
var config = require('./package.json'); | |
var del = require('del'); | |
var browserify = require('browserify'); | |
var babelify = require('babelify'); | |
var exorcist = require('exorcist'); | |
var watchify = require('watchify'); | |
var source = require('vinyl-source-stream'); | |
var sass = require('gulp-sass'); | |
var jade = require('gulp-jade'); | |
var sourcemaps = require('gulp-sourcemaps'); | |
var gulpif = require('gulp-if'); | |
var plumber = require('gulp-plumber'); | |
var gutil = require('gulp-util'); | |
var notify = require("gulp-notify"); | |
var browserSync = require('browser-sync'); | |
var debugMode = false; | |
var errorHandler = function () { | |
if (!debugMode) { | |
return; | |
} | |
notify.onError({ | |
title: "Compile Error", | |
message: "<%= error %>" | |
}).apply(this, Array.prototype.slice.call(arguments)); | |
this.emit('end'); | |
}; | |
var updateLogger = function (target) { | |
gutil.log(gutil.colors.green('Recreating "' + target + '"...')); | |
}; | |
gulp.task('enableDebug', function () { | |
debugMode = true; | |
}); | |
gulp.task('clean', function (done) { | |
return del([config.paths.build], done); | |
}); | |
gulp.task('browserify', function () { | |
// For shim and transformation configurations, see 'package.json'. | |
var bundler = browserify({ | |
entries: [config.paths.mainScript], | |
extensions: ['.jsx'], | |
cache: {}, | |
packageCache: {}, | |
debug: debugMode, | |
fullPaths: debugMode | |
}).transform(babelify, {compact: false, ignore: "bower_components"}); | |
var bundle = function () { | |
return bundler.bundle() | |
.on('error', errorHandler) | |
.pipe(exorcist('./build/bundle.js.map', null, null, '../src')) | |
.pipe(source('bundle.js')) | |
.pipe(gulp.dest(config.paths.build)) | |
.pipe(gulpif(debugMode, browserSync.reload({stream: true}))); | |
}; | |
if (debugMode) { | |
bundler = watchify(bundler); | |
bundler.on('update', function () { | |
updateLogger('JavaScript bundle'); | |
return bundle(); | |
}); | |
} | |
return bundle(); | |
}); | |
gulp.task('sass', function () { | |
return gulp.src(config.paths.styles) | |
.pipe(gulpif(debugMode, plumber({errorHandler: errorHandler}))) | |
.pipe(gulpif(debugMode, sourcemaps.init())) | |
.pipe(sass()) | |
.pipe(gulpif(debugMode, sourcemaps.write())) | |
.pipe(gulp.dest(config.paths.build)) | |
.pipe(gulpif(debugMode, browserSync.reload({stream: true}))); | |
}); | |
gulp.task('templates', function () { | |
return gulp.src(config.paths.jade) | |
.pipe(gulpif(debugMode, plumber({errorHandler: errorHandler}))) | |
.pipe(jade()) | |
.pipe(gulp.dest(config.paths.build)) | |
.pipe(gulpif(debugMode, browserSync.reload({stream: true}))); | |
}); | |
gulp.task('resources', function () { | |
return gulp.src([ | |
'bower_components/foundation-icon-fonts/foundation-icons.ttf', | |
'bower_components/foundation-icon-fonts/foundation-icons.woff', | |
config.paths.static | |
]) | |
.pipe(gulp.dest(config.paths.build)) | |
.pipe(gulpif(debugMode, browserSync.reload({stream: true}))); | |
}); | |
gulp.task('watch', function () { | |
gulp.watch(config.paths.styles, ['sass']).on('change', updateLogger.bind(null, 'SASS bundle')); | |
gulp.watch([config.paths.templates, config.paths.jade], ['templates']).on('change', updateLogger.bind(null, 'templates & Jade')); | |
gulp.watch([config.paths.static], ['resources']).on('change', updateLogger.bind(null, 'static resources')); | |
}); | |
gulp.task('samples', function () { | |
return gulp.src(config.paths.samples) | |
.pipe(gulp.dest(config.paths.build)); | |
}); | |
gulp.task('browserSync', function () { | |
browserSync({ | |
server: { | |
baseDir: config.paths.build, | |
directory: false | |
}, | |
port: parseInt(config.debugOptions.port), | |
logPrefix: 'sync -->', | |
logConnections: (config.debugOptions.logConnections === 'true'), | |
open: (config.debugOptions.openBrowser === 'true'), | |
minify: false, | |
ui: false | |
}); | |
}); | |
gulp.task('build', ['browserify', 'sass', 'templates', 'resources']); | |
gulp.task('rebuild', ['clean', 'build']); | |
gulp.task('default', ['enableDebug', 'build', 'watch', 'browserSync']); |
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
{ | |
"name": "app", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Foo Bar", | |
"license": "Qux", | |
"paths": { | |
"scripts": "./src/scripts/**/*.js", | |
"jsx": "./src/scripts/**/*.jsx", | |
"mainScript": "./src/scripts/main.jsx", | |
"styles": "./src/styles/**/*.scss", | |
"jade": "./src/templates/**/*.jade", | |
"templates": "./src/templates/**/*.html", | |
"static": "src/static/**/*", | |
"samples": "./test/sample/**/*", | |
"build": "./build/", | |
"package": "./package/" | |
}, | |
"debugOptions": { | |
"port": "4000", | |
"logConnections": "true", | |
"openBrowser": "false" | |
}, | |
"devDependencies": { | |
"babelify": "~6.3.0", | |
"bower": "^1.3.12", | |
"browser-sync": "^2.7.13", | |
"browserify": "^9.0.3", | |
"browserify-shim": "^3.8.9", | |
"deep-equal": "^1.0.1", | |
"del": "^1.1.1", | |
"gulp": "^3.8.11", | |
"gulp-if": "^1.2.5", | |
"gulp-jade": "^1.0.0", | |
"gulp-notify": "^2.2.0", | |
"gulp-plumber": "^1.0.1", | |
"gulp-sass": "^2.0.4", | |
"gulp-sourcemaps": "^1.5.2", | |
"gulp-util": "^3.0.6", | |
"gulp-webserver": "^0.9.0", | |
"qs": "^5.2.0", | |
"reactify": "^1.1.0", | |
"vinyl-source-stream": "^1.1.0", | |
"watchify": "^3.2.3" | |
}, | |
"dependencies": { | |
"exorcist": "^0.4.0", | |
"fuzzy": "^0.1.1", | |
"immutable": "^3.7.4", | |
"jquery": "^2.1.4", | |
"lodash": "^3.10.0", | |
"marked": "^0.3.3", | |
"react": "^0.14.0", | |
"react-dom": "^0.14.0", | |
"react-notification-system": "~0.2.5", | |
"react-router": "~1.0.0-rc1", | |
"react-select": "git://github.com/ingesy/react-select.git", | |
"vis": "~4.9.0", | |
"history": "~1.13.0", | |
"react-autosuggest": "~2.1.1", | |
"react-dnd": "~2.0.2", | |
"react-dnd-html5-backend": "~2.0.0" | |
}, | |
"browserify": { | |
"transform": [ | |
"browserify-shim", | |
"reactify" | |
] | |
}, | |
"browser": { | |
"modernizr": "./bower_components/modernizr/modernizr.js", | |
"foundation": "./bower_components/foundation/js/foundation.js", | |
"foundation-tooltip": "./bower_components/foundation/js/foundation/foundation.tooltip.js", | |
"foundation-topbar": "./bower_components/foundation/js/foundation/foundation.topbar.js", | |
"foundation-reveal": "./bower_components/foundation/js/foundation/foundation.reveal.js" | |
}, | |
"browserify-shim": { | |
"modernizr": { | |
"exports": "Modernizr" | |
}, | |
"foundation": { | |
"exports": "Foundation", | |
"depends": [ | |
"jquery:jQuery", | |
"modernizr:Modernizr" | |
] | |
}, | |
"foundation-tooltip": { | |
"depends": [ | |
"jquery:jQuery", | |
"foundation:Foundation" | |
] | |
}, | |
"foundation-topbar": { | |
"depends": [ | |
"jquery:jQuery", | |
"foundation:Foundation" | |
] | |
}, | |
"foundation-reveal": { | |
"depends": [ | |
"jquery:jQuery", | |
"foundation:Foundation" | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment