forked from CreativeIT/material-dashboard-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
132 lines (115 loc) · 4.27 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var gulp = require('gulp'),
jscs = require('gulp-jscs'),
babel = require('gulp-babel'),
inject = require('gulp-inject'),
plumber = require('gulp-plumber'),
watch = require('gulp-watch'),
livereload = require('gulp-livereload'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
clean = require('gulp-clean'),
del = require('del'),
browserSync = require('browser-sync');
var onError = function (err) {
console.log('An error occurred:', err.message);
this.emit('end');
};
gulp.task('check-js-style', function () {
gulp.src('src/**/*.js')
.pipe(jscs({fix: true}))
.pipe(jscs.reporter())
.pipe(jscs.reporter('fail'))
.pipe(gulp.dest('src'));
});
gulp.task('serve', ['default', 'watch'], function () {
var files = [
'./dist/*.html',
'./dist/css/**/*.css',
'./dist/js/**/*.js'
];
browserSync.init(files, {
server: {
baseDir: './dist'
}
});
});
gulp.task('scss', function () {
return gulp.src('./src/application.scss')
.pipe(plumber({errorHandler: onError}))
.pipe(sass())
.pipe(gulp.dest('./dist/css'));
});
gulp.task('babel', ['scss'], function () {
return gulp.src('src/**/*.js')
.pipe(plumber({errorHandler: onError}))
.pipe(babel())
.pipe(gulp.dest('./dist/js'));
});
gulp.task('watch', function () {
gulp.watch('./src/**/*.scss', ['default']);
gulp.watch('./src/**/*.js', ['default']);
gulp.watch('./src/**/*.html', ['default']);
});
gulp.task('jshint', ['babel', 'scss'], function () {
return gulp.src('src/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('default', ['cleanDist', 'jshint', 'babel', 'copyJsLib', 'copyCssLib'], function () {
gulp.src('src/images/**/*')
.pipe(gulp.dest('dist/images'));
gulp.src('src/**/*.html')
.pipe(gulp.dest('dist/'))
.pipe(inject(gulp.src(['dist/js/**/*.js', 'dist/css/lib/*.css', 'dist/css/*.css'], {read: false}), {relative: true}))
.pipe(gulp.dest('dist/'));
});
gulp.task('copyJsLib', ['cleanDist'], function () {
return gulp.src(['bower_components/material-design-lite/material.js', 'bower_components/d3/d3.js',
'bower_components/nvd3/build/nv.d3.js', 'bower_components/getmdl-select/getmdl-select.min.js'])
.pipe(gulp.dest('dist/js'));
});
gulp.task('copyMinJsLib', ['cleanDist'], function () {
return gulp.src(['bower_components/material-design-lite/material.min.js', 'bower_components/d3/d3.min.js',
'bower_components/nvd3/build/nv.d3.min.js', 'bower_components/getmdl-select/getmdl-select.min.js'])
.pipe(gulp.dest('dist/js'));
});
gulp.task('copyCssLib', ['cleanDist'], function () {
return gulp.src(['bower_components/nvd3/build/nv.d3.css', 'bower_components/getmdl-select/getmdl-select.min.css'])
.pipe(gulp.dest('dist/css/lib'));
});
gulp.task('copyMinCssLib', ['cleanDist'], function () {
return gulp.src(['bower_components/nvd3/build/nv.d3.min.css', 'bower_components/getmdl-select/getmdl-select.min.css'])
.pipe(gulp.dest('dist/css/lib'));
});
gulp.task('cleanDist', function () {
return del('dist/**/*');
});
gulp.task('minifyJs', ['cleanDist'], function () {
return gulp.src('src/**/*.js')
.pipe(rename({suffix: '.min'}))
.pipe(plumber({errorHandler: onError}))
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('dist/js'));
});
gulp.task('minifyCss', ['cleanDist'], function () {
return gulp.src('src/application.scss')
.pipe(plumber({errorHandler: onError}))
.pipe(sass())
.pipe(minifycss())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist/css'));
});
gulp.task('build', ['minifyJs', 'minifyCss', 'copyMinCssLib', 'copyMinJsLib'], function () {
gulp.src('src/*.html')
.pipe(gulp.dest('dist/'))
.pipe(inject(gulp.src(['dist/js/**/*.js', 'dist/css/lib/*.css',
'dist/css/*.css'], {read: false}), {relative: true}))
.pipe(gulp.dest('dist/'));
gulp.src('src/images/**/*')
.pipe(gulp.dest('dist/images'));
});