-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
60 lines (53 loc) · 1.58 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
'use strict';
var gulp = require('gulp'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
babelify = require('babelify'),
plumber = require('gulp-plumber'),
uglify = require('gulp-uglify'),
browserSync = require('browser-sync'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps');
// local server
gulp.task('server', function() {
browserSync({
server: {
baseDir: "./",
index: "index.html"
}
});
});
// reload browser
gulp.task('reload', function() {
browserSync.reload();
});
// compile react .jsx files
gulp.task('react', function(){
browserify('./js/main.jsx', { debug: true })
.transform(babelify)
.bundle()
.on("error", function (err) { console.log("Error : " + err.message); })
.pipe(source('main.js'))
.pipe(plumber())
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/'));
});
// compile scss files
gulp.task('sass', function() {
gulp.src('./scss/**/*.scss')
.pipe(plumber())
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
// file watch and run tasks
gulp.task('watch', function() {
gulp.watch(['./*.html', './css/**/*.css', './dist/**/*.js'], ['reload']);
// gulp.watch(['./css/**/*.css'], ['Css']);
gulp.watch(['./scss/**/*.scss'], ['sass']);
gulp.watch(['./js/*.js', './js/*.jsx'], ['react']);
});
gulp.task('default', ['server', 'sass', 'react', 'watch']);