Created
October 21, 2015 21:23
-
-
Save shrunyan/88f6b33f64e1827f7f91 to your computer and use it in GitHub Desktop.
Riot build with Gulp, Browserify, Riotify, Babel and gulp-connect
This file contains hidden or 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
/* global require */ | |
var source = require('vinyl-source-stream') | |
var buffer = require('vinyl-buffer') | |
var browserify = require('browserify') | |
var watchify = require('watchify') | |
var riotify = require('riotify') | |
var babelify = require('babelify') | |
module.exports = function (gulp, plugins) { | |
return function () { | |
var b = browserify(watchify.args) | |
b.external(gulp.opts.VENDORS) | |
b.add(gulp.opts.APP_ENTRY) | |
b.transform(babelify) | |
b.transform(riotify) | |
b.bundle() | |
.pipe(source('bundle.js')) | |
.pipe(buffer()) | |
.pipe(plugins.sourcemaps.init()) | |
.pipe(plugins.uglify()) | |
.pipe(plugins.sourcemaps.write('./maps')) | |
.pipe(gulp.dest(gulp.opts.DEST)) | |
return b | |
} | |
} |
This file contains hidden or 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
/* global require:true */ | |
var gulp = require('gulp') | |
var plugins = require('gulp-load-plugins')() | |
var minimist = require('minimist') | |
var assign = require('lodash-node/modern/object/assign') | |
var env = { | |
string: 'env', | |
default: { | |
env: process.env.NODE_ENV || 'development' | |
} | |
} | |
var argv = minimist(process.argv.slice(2), env) | |
var options = { | |
DEST: 'public', | |
APP_ENTRY: 'app/app.js', | |
LESS: [ | |
'app/core/less/**/*.less', | |
'app/less/**/*.less' | |
], | |
VENDORS: [ | |
'app/vendors/**/*.js' | |
] | |
} | |
function getTask(task) { | |
return require('./tasks/' + task)(gulp, plugins) | |
} | |
gulp.opts = assign(options, argv) | |
// Load Tasks | |
gulp.task('html', getTask('html')) | |
gulp.task('icons', getTask('icons')) | |
gulp.task('less', getTask('less')) | |
gulp.task('vendors', getTask('vendors')) | |
gulp.task('bundle', getTask('bundle')) | |
gulp.task('rebundle', getTask('rebundle')) | |
gulp.task('serve', getTask('serve')) | |
// Build Tasks | |
gulp.task('build', ['html', 'icons', 'less', 'vendors', 'bundle']) | |
gulp.task('watch', ['rebundle'], function () { | |
gulp.watch(gulp.opts.LESS, ['less']) | |
}) | |
gulp.task('dev', ['serve', 'build', 'watch']) | |
gulp.task('default', ['dev']) |
This file contains hidden or 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
module.exports = function (gulp, plugins) { | |
return function () { | |
gulp.src('app/index.html') | |
.pipe(gulp.dest(gulp.opts.DEST)) | |
} | |
} |
This file contains hidden or 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
module.exports = function (gulp, plugins) { | |
return function () { | |
gulp.src('app/less/core/icons/*') | |
.pipe(gulp.dest(gulp.opts.DEST + '/icons')) | |
} | |
} |
This file contains hidden or 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
module.exports = function (gulp, plugins) { | |
return function () { | |
gulp.src(gulp.opts.LESS) | |
.pipe(plugins.plumber()) | |
.pipe(plugins.less()) | |
.pipe(plugins.minifyCss({ | |
compatibility: 'ie8' | |
})) | |
.pipe(plugins.concat('main.min.css')) | |
.pipe(gulp.dest(gulp.opts.DEST)) | |
} | |
} |
This file contains hidden or 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
/* global require */ | |
var source = require('vinyl-source-stream') | |
var buffer = require('vinyl-buffer') | |
var watchify = require('watchify') | |
module.exports = function (gulp, plugins) { | |
var browserify = require('./bundle')(gulp, plugins)() | |
return function () { | |
var w = watchify(browserify) | |
// Watch and rebundle | |
w.on('update', function () { | |
w.bundle() | |
.pipe(source('bundle.js')) | |
.pipe(buffer()) | |
.pipe(gulp.dest(gulp.opts.DEST)) | |
.pipe(plugins.connect.reload()); | |
}) | |
w.on('log', function (msg) { | |
console.log(msg) | |
}) | |
return w | |
} | |
} |
This file contains hidden or 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
module.exports = function (gulp, plugins) { | |
return function () { | |
var host = gulp.opts.env == 'development' ? 'localhost' : '0.0.0.0' | |
var port = gulp.opts.env == 'development' ? 8001 : 80 | |
plugins.connect.server({ | |
root: gulp.opts.DEST, | |
host: host, | |
port: port, | |
livereload: true | |
}) | |
} | |
} |
This file contains hidden or 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
module.exports = function (gulp, plugins) { | |
return function () { | |
gulp.src(gulp.opts.VENDORS) | |
.pipe(plugins.concat('vendors.js')) | |
.pipe(plugins.sourcemaps.init()) | |
.pipe(plugins.uglify()) | |
.pipe(plugins.sourcemaps.write('./maps')) | |
.pipe(gulp.dest(gulp.opts.DEST)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment