-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
66 lines (57 loc) · 1.73 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
'use strict';
const watchify = require('watchify');
const browserify = require('browserify');
const babelify = require("babelify");
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const log = require('gulplog');
const sourcemaps = require('gulp-sourcemaps');
const assign = require('lodash.assign');
var uglify = require('gulp-uglify');
const gulp = require('gulp');
const sass = require('gulp-sass');
const rename = require('gulp-rename');
var webserver = require('gulp-webserver');
// add custom browserify options here
var customOpts = {
entries: ['./src/index.js'],
debug: false,
sourceType: module
};
var opts = assign({}, watchify.args, customOpts);
var b = watchify(browserify(opts));
// add transformations here
b.transform(babelify, {presets: ["es2015"]});
gulp.task('js', function () {
return b.bundle()
.on('error', log.error.bind(log, 'Browserify Error'))
.pipe(source('app.min.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'));
});
gulp.task('webserver', function () {
gulp.src('./').pipe(webserver({
livereload: true,
host: '127.0.0.1',
port: 8080,
open: true,
fallback: './index.html'
}));
});
gulp.task('sass', function () {
return gulp.src('./assets/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(rename('app.min.css'))
.pipe(gulp.dest('./dist'));
});
gulp.task('sass:watch', function () {
gulp.watch('./assets/scss/**/*.scss', ['sass']);
});
gulp.task('js:watch', function () {
gulp.watch(['./assets/lang/**/*.js', './src/**/*.js'], ['js']);
});
gulp.task('build', ['sass', 'js']);
gulp.task('default', ['sass:watch', 'js:watch', 'webserver']);