-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
118 lines (91 loc) · 3.09 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
var gulp = require('gulp'),
sass = require('gulp-sass')
minifycss = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
notify = require('gulp-notify'),
concat = require('gulp-concat'),
cache = require('gulp-cache'),
cssmin = require('gulp-cssmin'),
livereload = require('gulp-livereload');
plumber = require('gulp-plumber');
var config = {
// If you do not have the live reload extension installed,
// set this to true. We will include the script for you,
// just to aid with development.
// We recommend to use the Chrome extension for LiveReload
appendLiveReload: false,
// Should CSS & JS be compressed?
minifyCss: true,
uglifyJS: true
};
var vendorName = 'Ecommerce121';
var themeName = 'exercise4';
var webPath = 'web/';
var rootPath = '../../../../../pub/static/frontend/' + vendorName + '/' + themeName + '/en_US/';
// Sass
gulp.task('css', function() {
var stream = gulp.src(webPath + 'scss/styles.scss')
.pipe(plumber())
.pipe(sass({errLogToConsole: true}))
.on('error', function (err) {
console.log(err.message);
this.emit('end');
})
.pipe(cssmin())
.pipe(gulp.dest(webPath + 'css'))
.pipe(gulp.dest(rootPath + 'css'));
if (config.minifyCss === true) {
stream.pipe(minifycss({keepSpecialComments: '0'}));
}
stream.pipe(livereload());
return stream.pipe(notify({ message: 'Sass compiled succesfully!' }));
});
// JS
gulp.task('js', function() {
/* Here you need to append your custom codes placed on js/custom folder */
var scripts = [
webPath + 'js/custom/_my_custom_scripts.js',
];
if (config.appendLiveReload === true) {
scripts.push(webPath + 'js/livereload.js');
}
var stream = gulp
.src(scripts)
.pipe(concat('script.js'));
if (config.uglifyJS === true) {
stream.pipe(uglify());
}
stream.pipe(gulp.dest(webPath + 'js'));
stream.pipe(gulp.dest(rootPath + 'js'));
stream.pipe(livereload());
return stream.pipe(notify({ message: 'Successfully compiled JavaScript' }));
});
// Images
gulp.task('images', function() {
return gulp
.src(webPath + 'images/**/*')
.pipe(gulp.dest(webPath + 'images'))
.pipe(gulp.dest(rootPath + 'images'))
.pipe(livereload())
.pipe(notify({ message: 'Successfully processed image' }));
});
// Default task
gulp.task('default', [], function() {
gulp.start('css', 'js', 'images');
});
// Watch
gulp.task('watch', function() {
livereload.listen();
// Watch .less files
gulp.watch(webPath + 'scss/**/*.scss', ['css']);
// Watch .js files
gulp.watch(webPath + 'js/**/*.js', ['js']);
// Watch image files
gulp.watch(webPath + 'images/**/*', ['images']);
// Create LiveReload server
var server = livereload();
// Watch any files in , reload on change
gulp.watch([webPath + 'css/style.css', webPath + 'images/!**!/!*']).on('change', function(file) {
server.changed(file.path);
});
});