forked from QLevaslot/task-hero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (85 loc) · 2.54 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
var gulp = require('gulp');
var gulpAutoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync');
var gulpConcat = require('gulp-concat');
var gulpSass = require('gulp-sass');
var gulpSourcemaps = require('gulp-sourcemaps');
var babelify = require('babelify');
var browserify = require('browserify');
var eslintify = require('eslintify');
var reactify = require('reactify');
var vinylSourceStream = require('vinyl-source-stream');
var vinylBuffer = require('vinyl-buffer');
var watchify = require('watchify');
// Build javascript files with browserify, reactify and babelify
function compile(watch) {
var plugin = [];
if (watch) {
plugin = [[watchify, {ignoreWatch: ['**/node_modules/**']}]]
}
var bundler = browserify({
entries: "./src/index.jsx",
debug: true,
cache: {},
packageCache: {},
plugin: plugin,
transform: [["eslintify"], ["babelify", {"presets": ["es2015", "react", "stage-2"]}]]
});
function rebundle() {
console.log('-> bundling...');
return bundler.bundle()
.on('error', function (err) {
console.error(err);
})
.pipe(vinylSourceStream('build.js'))
.pipe(vinylBuffer())
.pipe(gulpSourcemaps.init({loadMaps: true}))
.pipe(gulpSourcemaps.write('./'))
.pipe(gulp.dest('./build'));
}
if (watch) {
bundler.on('update', function () {
rebundle();
});
bundler.on("time", function (time) {
console.log(" bundling done in " + time + "ms");
});
}
return rebundle();
}
// Compile sass files into CSS
function sass() {
return gulp.src("src/assets/sass/main.scss")
.pipe(gulpSourcemaps.init())
.pipe(gulpSass({
outputStyle: "compressed",
includePaths: ["node_modules/"]
}).on("error", gulpSass.logError))
.pipe(gulpAutoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulpConcat("main.css"))
.pipe(gulpSourcemaps.write("./"))
.pipe(gulp.dest("build/"));
}
gulp.task('sass', function(){return sass();});
gulp.task('compile', function(){return compile();});
gulp.task('build', gulp.series('sass', 'compile'));
gulp.task('watch', function () {
sass();
gulp.watch('src/assets/sass/**/*.scss', sass);
compile(true);
});
gulp.task('browsersync', function () {
// Just want static server, no need for hot reload as of now
return browserSync({
server: {
baseDir: '.'
},
notify: false
});
});
gulp.task('watchAndLaunch', gulp.parallel('watch', 'browsersync'));
// default task
gulp.task('default', gulp.series('watchAndLaunch'));