forked from srijanone/ezcontent_theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
92 lines (82 loc) · 2.43 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
'use strict';
var gulp = require('gulp');
var argv = require('yargs').argv;
var sassLint = require('gulp-sass-lint');
var autoprefixer = require('gulp-autoprefixer');
var babel = require('gulp-babel');
var bs = require('browser-sync').create();
var pixrem = require('gulp-pixrem');
var sass = require('gulp-sass');
var sassGlob = require('gulp-sass-glob');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var paths = {
//sassSrc: './scss/**/**/*.{scss,sass}',
sassSrc: './pattern-lab/source/_patterns/**/**/*.{scss,sass}',
sassDest: 'css',
jsSrc: ['js/source/*.js', 'js/component/*.js'],
jsDest: 'js/build',
imgSrc: 'images/source/**/*.{png,jpg,gif}',
imgDest: 'images/optimized',
svgSrc: 'images/source/**/*.svg',
svgDest: 'images/optimized'
}
var browserList = ['last 5 versions', '> 5%', 'Firefox ESR'];
gulp.task('scss', function () {
return gulp.src(paths.sassSrc)
.pipe(sourcemaps.init())
.pipe(sassGlob())
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError)) // use for dev (expanded)
// Need the next two lines as an intermediate write, otherwise autoprefizer doesnt cooperate with sourcemaps
// https://github.com/ByScripts/gulp-sample/blob/master/gulpfile.js
.pipe(sourcemaps.write({includeContent: false}))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(autoprefixer({browsers: browserList}))
.pipe(pixrem())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.sassDest))
.pipe(bs.stream());
});
gulp.task('js', function() {
return gulp.src(paths.jsSrc)
.pipe(sourcemaps.init())
.pipe(babel({
presets: [
['env', {
targets: {
browsers: browserList
}
}]
]
}))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.jsDest));
});
gulp.task('sass-lint', function() {
return gulp.src(paths.sassSrc)
.pipe(sassLint({
configFile: '.sasslintrc'
}))
.pipe(sassLint.format())
.pipe(sassLint.failOnError())
});
// Watch files for change and set Browser Sync
gulp.task('watch', function() {
bs.init({
files: [
'css/**/*.css',
'templates/**/*.twig',
'images/optimized/**/*.{png,jpg,gif,svg}',
'js/build/**/*.js',
'*.theme'
],
proxy: argv.proxy
});
gulp.watch(paths.sassSrc, ['scss']);
gulp.watch(paths.jsSrc, ['js']).on('change', bs.reload);
});
// Default task
gulp.task('default', gulp.series('scss', 'js', 'sass-lint', 'watch'));
// Build Prod
gulp.task('build:prod', gulp.series('scss', 'js', 'sass-lint'));