forked from Riccardo-Zanutta/brick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
99 lines (87 loc) · 2.89 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
89
90
91
92
93
94
95
96
97
98
99
/**
* BRick
* https://github.com/Riccardo-Zanutta/brick
* Copyright 2016 Riccardo Zanutta (@RiccardoZanutta)
* Released under the MIT license (http://mit-license.org)
*/
'use strict';
import gulp from 'gulp';
import config from './config.json';
import pkg from './package.json';
import gulpLoadPlugins from 'gulp-load-plugins';
import browserSync from 'browser-sync';
import del from 'del';
import runSequence from 'run-sequence';
import merge from 'merge2';
import { argv } from 'yargs';
const $ = gulpLoadPlugins();
const reload = browserSync.reload;
// List all tasks and subtasks
gulp.task('help', $.taskListing);
// Sass compile, autprefixer, minify, sourcemaps
gulp.task('styles', () => {
return gulp.src(config.sass_src)
.pipe($.if(argv.pretty, $.sourcemaps.init()))
.pipe($.sass({
precision: 10,
includePaths: ['.src/css/']
}).on('error', $.sass.logError))
.pipe($.autoprefixer(config.autoprefixer_options))
.pipe($.if(!argv.pretty, $.cssnano()))
.pipe($.size({title: 'Styles'}))
.pipe($.if(argv.pretty, $.sourcemaps.write('./')))
.pipe(gulp.dest(config.sass_dest))
});
// Concat, babelify, sourcemaps and minify js files
gulp.task('scripts', () => {
return merge(
gulp.src(config.js_vendor_src)
.pipe($.size({title: 'Vendor scripts'})),
gulp.src(config.js_build_src)
.pipe($.babel())
)
.pipe($.if(argv.pretty, $.sourcemaps.init()))
.pipe($.concat(config.js_file_name))
.pipe($.if(!argv.pretty, $.uglify({preserveComments: 'some'})))
.pipe($.if(argv.pretty, $.sourcemaps.write('./')))
.pipe($.size({title: 'Scripts'}))
.pipe(gulp.dest(config.js_dest));
});
// Clean the dist/ folder
gulp.task('clean', () => {
return del.sync([
config.del_folder
])
});
// Copy the content from src/ to dist/
gulp.task('copy', ['clean'], () => {
return gulp.src(config.src_folder)
.pipe($.size({title: 'Copying ./src content in ./dist'}))
.pipe(gulp.dest(config.dist_folder))
});
// Serve the content, live reload with browsersync
gulp.task('serve', ['styles', 'scripts'], () => {
browserSync.init({
notify: false,
server: {
baseDir: './src'
},
port: config.port
});
gulp.watch('./src/*.html').on('change', reload);
gulp.watch(['./src/css/**/*.scss'], ['styles', reload]);
gulp.watch(['./src/js/vendor/*.js', './src/js/build/*.js'], ['scripts', reload]);
});
gulp.task('production', ['styles', 'scripts'], () => {
runSequence('copy');
});
// This is the default task :)
gulp.task('default', ['clean'], () => {
const startTime = Date.now();
runSequence('serve', () => {
console.log('\x1b[42m************************************\x1b[0m\n');
console.log('\x1b[32m BRick is ready to Rock!\x1b[0m\n');
console.log('\x1b[42m************************************\x1b[0m\n');
console.log('[\x1b[32mBRick\x1b[0m]', `All finished in \x1b[35m${Date.now() - startTime} ms` ,'\x1b[0m\n');
})
});