Skip to content

Instantly share code, notes, and snippets.

@Whoaa512
Created October 15, 2015 04:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Whoaa512/aa13bd6e3208cfd5e083 to your computer and use it in GitHub Desktop.
Save Whoaa512/aa13bd6e3208cfd5e083 to your computer and use it in GitHub Desktop.
Gulpfile for simple elm project
var concat = require('gulp-concat')
var concatCss = require('gulp-concat-css')
var csso = require('gulp-csso')
var del = require('del')
var elmBins = require('elm')
var glob = require('glob')
var gulp = require('gulp')
var jade = require('gulp-jade')
var jadeConcat = require('gulp-jade-template-concat')
var simpleSpawner = require('simple-spawner')
var paths = {
dist: 'build',
css: 'src/styles/*.css',
elm: 'src/elm/**/*.elm',
images: 'src/images/*',
index: 'src/index.html',
js: 'src/js/*.js',
templates: 'src/templates/*.jade'
}
function clean () {
return del(paths.dist)
}
function copyIndex () {
return gulp.src(paths.index)
.pipe(gulp.dest(paths.dist))
}
function css () {
return gulp.src(paths.css)
.pipe(concatCss('main.css', {
includePaths: [
'node_modules/normalize.css/'
]
}))
.pipe(csso())
.pipe(gulp.dest(paths.dist))
}
function elm () {
var elmPaths = glob.sync(paths.elm)
var args = elmPaths.concat([
'--yes',
'--output',
paths.dist + '/Main.js'
])
return simpleSpawner(elmBins['elm-make'], args)
}
function images () {
return gulp.src(paths.images)
.pipe(gulp.dest(paths.dist + '/images'))
}
function js () {
return gulp.src(paths.js)
.pipe(concat('vendor.js'))
.pipe(gulp.dest(paths.dist + '/js'))
}
function templates () {
return gulp.src(paths.templates)
.pipe(jade({ client: true }))
.pipe(jadeConcat('templates.js', { templateVariable: 'templates' }))
.pipe(gulp.dest(paths.dist + '/js'))
}
function watch () {
var pathMap = {
css: css,
elm: elm,
images: images,
index: copyIndex,
js: js
}
Object.keys(pathMap).forEach(function (p) {
gulp.watch(paths[p], pathMap[p])
})
}
/* Tasks */
var parallelBuild = [
copyIndex,
images,
js,
css,
templates,
elm
]
// Add a named task for each step
parallelBuild.forEach(function (fn) { gulp.task(fn) })
var buildTasks = [
clean,
gulp.parallel(parallelBuild)
]
gulp.task(clean)
gulp.task('default', gulp.series(buildTasks, watch))
gulp.task(watch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment