76 lines
1.6 KiB
JavaScript
76 lines
1.6 KiB
JavaScript
var path = require('path');
|
|
var browserify = require('browserify');
|
|
var watchify = require('watchify');
|
|
var source = require('vinyl-source-stream');
|
|
var gulp = require('gulp');
|
|
var newer = require('gulp-newer');
|
|
var clean = require('gulp-clean');
|
|
var less = require('gulp-less');
|
|
|
|
var package = require('./package.json');
|
|
|
|
var folders = {
|
|
src: 'src/',
|
|
dist: 'dist/'
|
|
};
|
|
|
|
var browserifyOpts = {
|
|
entries: [package.main],
|
|
transform: [],
|
|
extensions: ['.js', '.json'],
|
|
cache: {},
|
|
packageCache: {}
|
|
};
|
|
|
|
function blob(fpath, extension) {
|
|
return path.join(fpath, '**', '*.' + extension);
|
|
}
|
|
|
|
// Tasks
|
|
gulp.task('default', ['build']);
|
|
|
|
gulp.task('build', ['application', 'style', 'static']);
|
|
|
|
gulp.task('clean', function () {
|
|
gulp.src(folders.dist)
|
|
.pipe(clean());
|
|
});
|
|
|
|
// By domain
|
|
gulp.task('application', ['js']);
|
|
|
|
gulp.task('style', ['less']);
|
|
|
|
gulp.task('static', ['html', 'svg']);
|
|
|
|
// By file
|
|
gulp.task('html', function () {
|
|
gulp.src(blob(folders.src, 'html'))
|
|
.pipe(newer(folders.dist))
|
|
.pipe(gulp.dest(folders.dist));
|
|
});
|
|
|
|
gulp.task('js', function () {
|
|
var brow = browserify(browserifyOpts)
|
|
|
|
brow.bundle()
|
|
.pipe(source('index.js'))
|
|
.pipe(gulp.dest(folders.dist));
|
|
});
|
|
|
|
gulp.task('less', function () {
|
|
var srcs = [
|
|
blob(folders.src, 'css'),
|
|
blob(folders.src, 'less')
|
|
];
|
|
|
|
gulp.src(srcs)
|
|
.pipe(less())
|
|
.pipe(gulp.dest(folders.dist));
|
|
});
|
|
|
|
gulp.task('svg', function () {
|
|
gulp.src(blob(folders.src, 'svg'))
|
|
.pipe(newer(folders.dist))
|
|
.pipe(gulp.dest(folders.dist));
|
|
}); |