1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-10 12:24:20 +01:00
ipfs-boards/gulpfile.js

98 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-11-14 00:57:36 +01:00
var gulp = require('gulp')
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var minifyCss = require('gulp-minify-css')
var browserify = require('browserify')
var uglify = require('gulp-uglify')
var clean = require('gulp-clean')
var exorcist = require('exorcist')
2015-11-14 01:34:03 +01:00
var connect = require('gulp-connect')
2015-11-15 21:34:41 +01:00
var watchify = require('watchify')
2015-11-14 00:57:36 +01:00
var config = {
files: {
2015-11-14 01:34:03 +01:00
mainJs: 'webapp/app.jsx',
2015-11-14 00:57:36 +01:00
css: 'webapp/*.css',
2015-11-14 01:34:03 +01:00
js: ['webapp/*.js','webapp/*.jsx'],
2015-11-14 15:03:38 +01:00
html: 'webapp/*.html',
jsLibs: 'lib/*.js'
2015-11-14 00:57:36 +01:00
},
dest: 'webapp/dist/'
}
gulp.task('css',function(){
gulp.src(config.files.css)
.pipe(minifyCss())
.pipe(gulp.dest(config.dest))
2015-11-14 01:34:03 +01:00
.pipe(connect.reload())
2015-11-14 00:57:36 +01:00
})
gulp.task('html',function(){
2015-11-15 21:34:41 +01:00
return gulp.src(config.files.html)
2015-11-14 00:57:36 +01:00
.pipe(gulp.dest(config.dest))
2015-11-14 01:34:03 +01:00
.pipe(connect.reload())
2015-11-14 00:57:36 +01:00
})
gulp.task('js',function(){
2015-11-15 21:34:41 +01:00
return applyBrowserify(getBrowserify())
2015-11-14 00:57:36 +01:00
})
2015-11-15 21:34:41 +01:00
gulp.task('js-watch',function(){
var b = watchify(getBrowserify())
2015-11-16 11:55:59 +01:00
b.on('error',function(error){
console.log(error)
})
2015-11-15 21:34:41 +01:00
b.on('update', function(){
2015-11-16 11:55:59 +01:00
console.log('Rebundling')
2015-11-15 21:34:41 +01:00
applyBrowserify(b)
})
return b
})
2015-11-15 21:34:41 +01:00
function getBrowserify(){
return browserify(config.files.mainJs, {
cache: {},
packageCache: {},
fullPaths: true,
debug: true })
.transform('babelify', {
global: true,
presets: [ 'es2015', 'react' ],
ignore: /buffer|EventEmitter/
})
.transform('eslintify')
.transform({ global: true },'uglifyify')
}
function applyBrowserify(b){
return b.bundle()
.pipe(exorcist(__dirname+'/webapp/dist/app.js.map'))
.on('error', console.error.bind(console))
.pipe(source('app.js'))
.pipe(buffer())
.pipe(gulp.dest(config.dest))
.pipe(connect.reload())
}
2015-11-14 00:57:36 +01:00
gulp.task('clean',function(){
2015-11-15 21:34:41 +01:00
return gulp.src(config.dest, { read: false }).pipe(clean())
2015-11-14 00:57:36 +01:00
})
gulp.task('server',function(){
2015-11-14 01:34:03 +01:00
connect.server({
root: config.dest,
port: 9090,
livereload: true
})
2015-11-14 01:34:03 +01:00
})
2015-11-16 11:55:59 +01:00
gulp.task('watch',['js-watch'],function(){
//gulp.watch([config.files.jsLibs,config.files.mainJs],['js-watch'])
2015-11-14 00:57:36 +01:00
gulp.watch(config.files.html,['html'])
gulp.watch(config.files.css,['css'])
})
gulp.task('serve', [ 'html', 'css', 'js', 'watch', 'server' ])
gulp.task('default', [ 'html', 'css', 'js' ])