-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
88 lines (79 loc) · 2.11 KB
/
gulpfile.babel.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
// Dependencies
import gulp from 'gulp';
import sass from 'gulp-sass';
import cssnano from 'gulp-cssnano';
import sourcemaps from 'gulp-sourcemaps';
import watch from 'gulp-watch';
import combinemq from 'gulp-combine-mq';
import webpack_stream from 'webpack-stream';
import gutil from 'gutil';
import plumber from 'gulp-plumber';
import uglifyPlugin from 'uglifyjs-webpack-plugin';
import notify from 'gulp-notify';
import webpack from 'webpack';
// Local Variables
const internals = {};
// Configuration
internals.supportedBrowsers = [ 'last 2 versions' ];
// Error Handler
internals.onError = function(error) {
notify({
title: 'Asset compiling error',
message: 'Check the console for details.'
}).write(error.message);
console.log(error.message);
this.emit('end');
};
// Destructuring internals
const { onError, supportedBrowsers } = internals;
gulp.task('sass', () => {
return gulp.src('./dev/sass/**/master.scss')
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(combinemq())
.pipe(cssnano({
autoprefixer: { browsers: supportedBrowsers, add: true }
}))
.pipe(sourcemaps.write('maps/'))
.pipe(gulp.dest('./build/css'));
});
gulp.task('js_bundler', () => {
return gulp.src('./dev/js/main.js')
.pipe(plumber({
errorHandler: () => {
console.log('error');
}
}))
.pipe(webpack_stream({
watch: true,
cache: true,
output: { filename: 'bundle.js' },
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use:[{
loader: 'babel-loader',
options: {
presets: ['es2015','react','stage-0'],
comments: false
}
},
{
loader: 'eslint-loader'
}]
}
]
},
plugins: [new uglifyPlugin({output: {comments: false}})]
}, webpack))
.pipe(gulp.dest('./build/js/'))
.pipe(notify('Bundler completed'));
});
// WATCHERS
gulp.task('watch', () => {
gulp.watch('./dev/sass/**/*.scss', ['sass']);
// gulp.watch('./dev/js/**/*.js', ['js_bundler']);
});
gulp.task('default', ['sass','js_bundler', 'watch']);