-
Notifications
You must be signed in to change notification settings - Fork 122
/
gulpfile.js
134 lines (117 loc) · 3.45 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
133
134
var gulp = require('gulp'),
eslint = require('gulp-eslint'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify'),
rename = require("gulp-rename"),
csslint = require('gulp-csslint'),
browserSync = require('browser-sync').create(),
gutil = require('gulp-util'),
webpack = require('webpack'),
cleanCSS = require('gulp-clean-css'),
sourcemaps = require('gulp-sourcemaps'),
path = require('path'),
del = require('del'),
merge = require('merge-stream'),
plumber = require('gulp-plumber');
gulp.task('cleanCSS', function() {
return del(['build/css']);
});
gulp.task('cleanJS', function() {
return del(['build/js']);
});
gulp.task('csslint', function() {
gulp.src('src/*.css')
.pipe(csslint({
'adjoining-classes': false,
'box-sizing': false,
'box-model': false,
'fallback-colors': false,
'order-alphabetical': false
}))
.pipe(csslint.formatter());
});
gulp.task('css', ['csslint', 'cleanCSS'], function() {
return gulp.src('src/*.css')
.pipe(sourcemaps.init())
.pipe(cleanCSS())
.pipe(rename('orgchart.min.css'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/css'))
.pipe(gulp.dest('demo/css'));
});
gulp.task('eslint', function () {
return gulp.src(['src/*.js'])
.pipe(eslint('.eslintrc.json'))
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('js', ['eslint', 'cleanJS'], function () {
return gulp.src(['src/*.js'])
.pipe(sourcemaps.init())
.pipe(babel(
{presets: ['es2015']}
))
.pipe(uglify())
.pipe(rename('orgchart.min.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/js'))
.pipe(gulp.dest('demo/js'));
});
gulp.task('watch', function () {
gulp.watch('src/*.js', ['js']);
gulp.watch('src/*.css', ['css']);
});
gulp.task('copyVendorAssets', function() {
var fontawesomeCSS = gulp.src('node_modules/font-awesome/css/font-awesome.min.css')
.pipe(gulp.dest('demo/css/vendor'));
var fontawesomeFonts = gulp.src('node_modules/font-awesome/fonts/*')
.pipe(gulp.dest('demo/css/fonts'));
var html2canvas = gulp.src('node_modules/html2canvas/dist/html2canvas.min.js')
.pipe(gulp.dest('demo/js/vendor'));
return merge(fontawesomeCSS, fontawesomeFonts, html2canvas);
});
gulp.task('build', ['css', 'js', 'watch']);
gulp.task('webpack', ['build'], function () {
webpack(require('./webpack.config.js'), function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log('[webpack]', stats.toString());
});
});
gulp.task('serve', ['copyVendorAssets', 'webpack'], function () {
browserSync.init({
files: ['src/*.css', 'demo/**/*.html', 'demo/**/*.css', '!demo/css/vendor/*.css'],
server: 'demo',
socket: {
domain: 'localhost:3000'
}
});
gulp.watch('src/*.js', ['webpack']);
gulp.watch('demo/js/*').on('change', browserSync.reload);
gulp.watch(['demo/**/*.js', '!demo/js/*', '!demo/js/vendor/*', '!demo/**/bundle*.js']).on('change', function(file) {
webpack({
entry: file.path,
output: {
path: path.dirname(file.path),
filename: 'bundle.js'
},
devtool: 'source-map',
module: {
loaders: [
{
loader: 'babel',
query: {
presets: ['es2015']
}
}
]
}
}, function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
browserSync.reload();
});
});
});