-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
120 lines (98 loc) · 3.44 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict';
var config = require('./gulpconfig.json');
var paths = config.paths;
// Core references for this to work
var gulp = require('gulp'),
browserSync = require('browser-sync').create(),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
reload = browserSync.reload,
clean = require('gulp-clean'),
gulpSequence = require('gulp-sequence');
// var listing of files for dist build
var filesToDist = [
'./src/*.html',
'./src/css/**/*.*',
'./src/images/**/*.*',
'./src/js//**/*.js'
];
// Use for stand-alone autoprefixer
var gulpautoprefixer = require('gulp-autoprefixer');
// alternate vars if you want to use Postcss as a setup
var postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer');
// Gulp task when using gulp-autoprefixer as a standalone process
gulp.task('build:css', function () {
//gulp.src(paths.scss + '/{,*/}*.{scss,sass}')
gulp.src('./src/sass/{,*/}*.{scss,sass}')
.pipe(sourcemaps.init())
.pipe(sass({
errLogToConsole: true,
outputStyle: 'expanded' //alt options: nested, compact, compressed
}))
.pipe(gulpautoprefixer({
browsers: ['last 4 versions'],
cascade: false
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./src/css'))
.pipe(reload({ stream: true }));
});
// Static Server + watching scss/html files
gulp.task('serve', ['build:css'], function () {
browserSync.init({
server: "./src/",
port: 8080
});
gulp.watch('./src/sass/{,*/}*.{scss,sass}', ['build:css']);
gulp.watch("./src/*.html").on('change', browserSync.reload);
});
// Sass watcher
gulp.task('sass:watch', function () {
gulp.watch('./src/sass/{,*/}*.{scss,sass}', ['build:css'])
});
// Creates the initial files
gulp.task('init', gulpSequence('copy-assets', 'scripts'));
// Run: gulp jscripts.
// Copies file from src to assets & transpiles theme.js via Babel
gulp.task('jscripts', function () {
var scripts = [
// Entire Bootstrap4 JS bundle
paths.dev + '/js/bootstrap4/bootstrap.bundle.js',
// Custom JS file
paths.dev + '/js/*.js'
];
gulp.src(scripts)
.pipe(gulpif(customjs_filter, babel({
presets: [['@babel/env']]
})))
.pipe(gulp.dest(paths.js));
});
// Run: gulp copy-assets.
// Copy all needed dependency assets files from node_modules folder to src/js, src/scss folders
gulp.task('copy-assets', function () {
// Copy Slim Minified version of Jquery 3.*.* from node_modules
var stream = gulp.src(paths.node + 'jquery/dist/jquery.slim.min.js')
.pipe(gulp.dest(paths.js));
// Copy BS4 JS files
gulp.src(paths.node + 'bootstrap/dist/js/**/*.js')
.pipe(gulp.dest(paths.dev + '/js/bootstrap4'));
// Copy BS4 SCSS files
gulp.src(paths.node + 'bootstrap/scss/**/*.scss')
.pipe(gulp.dest(paths.scss + '/bootstrap4'));
return stream;
});
// resource cleaning task
gulp.task('clean', function () {
return gulp.src(['dist/*'], { read: false })
.pipe(clean());
});
// dist build tasks
// see var filesToDist for specific files
gulp.task('build:dist', ['clean'], function () {
// the base option sets the relative root for the set of files,
// preserving the folder structure
gulp.src(filesToDist, { base: './src/' })
.pipe(gulp.dest('dist'));
});
gulp.task('default', ['build:css', 'sass:watch', 'serve']);