-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.extended.js
103 lines (89 loc) · 3.06 KB
/
gulpfile.babel.extended.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
100
101
102
103
const gulp = require('gulp');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const babel = require('gulp-babel');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const minify = require('gulp-clean-css');
const settings = {
dest: 'assets/dist', // destination of compiled files
}
const files = {
scripts: [
// array of js files (* = all files. ** = all folders.):
'assets/javascript/*.js',
'assets/javascript/**/*.js',
],
styles: [
// array of sass files:
'assets/styles/**/*.scss',
'assets/styles/*.scss',
],
vendor: { // optional array for vendor files
scripts: [
'./node_modules/jquery/dist/jquery.js',
'./node_modules/bootstrap/dist/js/bootstrap.js',
],
styles: [
'./node_modules/bootstrap/dist/css/bootstrap.css',
],
},
}
// JavaScript: concat files together, compile es2015 to es5, minify
gulp.task('scripts', function() {
return gulp.src( files.scripts ) // array of files to be combined into app.js
.pipe(concat( 'app.js' ))
.pipe(babel()) // compile to ES5
.pipe(gulp.dest( settings.dest ))
.pipe(rename( 'app.min.js' ))
.pipe(uglify()) // minify
.pipe(gulp.dest( settings.dest ));
});
// CSS/SASS: compile scss to css, autoprefix, minify
gulp.task('sass', function () {
return gulp.src( files.styles ) // array of sass files
.pipe(sass().on('error', sass.logError))
.pipe(concat( 'style.scss' )) // combine SCSS files together
.pipe(gulp.dest( settings.dest ))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(rename('style.css'))
.pipe(gulp.dest( settings.dest ))
.pipe(rename('style.min.css'))
.pipe(minify({compatibility: 'ie8'}))
.pipe(gulp.dest( settings.dest ));
});
// VENDOR (same as scripts and sass tasks, but with different files and destination)
// javascript
gulp.task('vendor-scripts', function() {
return gulp.src( files.vendor.scripts )
.pipe(concat('vendor.js'))
.pipe(babel())
.pipe(gulp.dest( settings.dest ))
.pipe(rename('vendor.min.js'))
.pipe(uglify())
.pipe(gulp.dest( settings.dest ));
});
// css/sass
gulp.task('vendor-sass', function () {
return gulp.src( files.vendor.styles )
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(rename( 'vendor.css' ))
.pipe(gulp.dest( settings.dest ))
.pipe(rename( 'vendor.min.css' ))
.pipe(minify({compatibility: 'ie8'}))
.pipe(gulp.dest( settings.dest ));
});
gulp.task('watch', function() {
gulp.watch( files.scripts, ['scripts']);
gulp.watch( files.styles, ['sass']);
});
gulp.task('default', ['sass', 'scripts', 'watch']);
gulp.task('vendor', ['vendor-sass', 'vendor-scripts']);