-
Notifications
You must be signed in to change notification settings - Fork 23
/
gulpfile.js
78 lines (66 loc) · 1.89 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var gulp = require('gulp');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var minifyCSS = require('gulp-minify-css');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var jshint = require('gulp-jshint');
var paths = {
root: './',
index: './index.html',
src: {
scss: './src/scss/*scss',
js: './src/js/*.js',
jsIndex: './src/js/index.js',
jsMain: './src/js/material-photo-gallery.js'
},
dist: {
css: './dist/css',
js: './dist/js',
bundle: './dist/js/bundle.js'
}
};
gulp.task('init', ['scss', 'browserify', 'lint'], function() {
gulp.watch(paths.src.scss, ['scss']);
gulp.watch(paths.src.js, ['lint', 'browserify']);
});
gulp.task('scss', function() {
return gulp.src(paths.src.scss)
.pipe(sourcemaps.init())
.pipe(sass())
.on('error', handleError)
.pipe(postcss([
autoprefixer()
]))
.pipe(minifyCSS())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.dist.css));
});
gulp.task('browserify', function() {
return browserify(paths.src.jsIndex)
.bundle()
.on('error', handleError)
.pipe(source('material-photo-gallery.js'))
.pipe(buffer())
.pipe(gulp.dest(paths.dist.js))
.pipe(uglify())
.pipe(rename('material-photo-gallery.min.js'))
.pipe(gulp.dest(paths.dist.js));
});
gulp.task('lint', function() {
return gulp.src(paths.src.jsMain)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
// Handle errors and continue watching files
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
gulp.task('default', ['init']);