-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
103 lines (93 loc) · 2.79 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
"use strict";
const gulp = require('gulp');
const webpack = require('webpack-stream');
const sass = require('gulp-sass');
const outputFolder = 'public_html/dist';
const path = require('path');
const rev = require('gulp-rev');
const autoPrefixer = require('gulp-autoprefixer');
const imageMin = require('gulp-imagemin');
const watch = require('gulp-watch');
let webpackConfig = {
cache: true,
entry: './app/assets/js/main.js',
output: {
filename: '[name].js',
sourceMapFilename: '[name].map'
},
devtool: '#inline-source-map',
module: {
loaders: [
{
loader: 'babel',
test: /\.js$/,
exclude: /node_modules/,
query: {
presets: ['es2015']
}
}
]
}
};
gulp.task('default', ['sass', 'js', 'img']);
gulp.task('clean', function (cb) {
let fs = require('fs');
let deleteFolderRecursive = function (path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file, index) {
let curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
deleteFolderRecursive(outputFolder);
return cb();
});
gulp.task('img', ['clean'], function () {
return gulp.src('app/assets/img/*')
.pipe(imageMin({
optimizationLevel: 7,
progressive: true,
interlaced: true,
multipass: true
}))
.pipe(gulp.dest('public_html/dist'))
});
gulp.task('sass', ['clean'], function () {
return gulp.src('app/assets/scss/main.scss')
.pipe(
sass({
outputStyle: 'compressed',
sourceMapEmbed: true
})
)
.pipe(autoPrefixer({
browsers: ['last 2 versions']
}))
.pipe(rev())
.pipe(gulp.dest(outputFolder))
.pipe(rev.manifest('public_html/dist/assets.json', {
base: process.cwd() + '/public_html/dist',
merge: true
}))
.pipe(gulp.dest(outputFolder))
});
gulp.task('js', ['clean'], function () {
return gulp.src('app/assets/js/main.js')
.pipe(webpack(webpackConfig))
.pipe(rev())
.pipe(gulp.dest(outputFolder))
.pipe(rev.manifest('public_html/dist/assets.json', {
base: process.cwd() + '/public_html/dist',
merge: true
}))
.pipe(gulp.dest(outputFolder))
});
gulp.task('watch', function () {
gulp.watch(['app/assets/**/*.js', 'app/assets/**/*.scss'], ['js', 'sass']);
});