-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (66 loc) · 1.88 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
var gulp = require('gulp');
var source = require('vinyl-source-stream'); // Used to stream bundle for further handling
var browserify = require('browserify');
var watchify = require('watchify');
var reactify = require('reactify');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var gutil = require('gulp-util');
var add = require('gulp-add-src');
var uglify = require('gulp-uglify');
var streamify = require('gulp-streamify');
var htmlreplace = require('gulp-html-replace');
var path = {
IMG: 'src/images',
CSS: 'src/css/app.css',
HTML: 'src/index.html',
MINIFIED_OUT: 'react-slider.min.js',
OUT: 'react-slider.js',
DEST: 'dist',
DEST_BUILD: 'dist/build',
DEST_SRC: 'dist/src',
ENTRY_POINT: './src/js/app.js'
};
gulp.task('copy', function(){
gulp.src(path.HTML)
.pipe(gulp.dest(path.DEST));
gulp.src(path.CSS)
.pipe(gulp.dest(path.DEST+"/css/"));
});
gulp.task('watch', function() {
gulp.watch([path.CSS,path.HTML], ['copy']);
var watcher = watchify(browserify({
entries: [path.ENTRY_POINT],
transform: [reactify],
debug: true,
cache: {}, packageCache: {}, fullPaths: true
}));
return watcher.on('update', function () {
watcher.bundle()
.pipe(source(path.OUT))
.pipe(gulp.dest(path.DEST_SRC))
console.log('Updated');
})
.bundle()
.pipe(source(path.OUT))
.pipe(gulp.dest(path.DEST_SRC));
});
gulp.task('build', function(){
browserify({
entries: [path.ENTRY_POINT],
transform: [reactify],
})
.bundle()
.pipe(source(path.MINIFIED_OUT))
.pipe(streamify(uglify()))
.pipe(gulp.dest(path.DEST_BUILD));
});
gulp.task('replaceHTML', function(){
gulp.src(path.HTML)
.pipe(htmlreplace({
'js': 'build/' + path.MINIFIED_OUT
}))
.pipe(gulp.dest(path.DEST));
});
gulp.task('production', ['replaceHTML', 'build']);
gulp.task('default', ['watch']);