This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
152 lines (133 loc) · 4.01 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const path = require('path')
const gulp = require('gulp')
const pug = require('gulp-pug')
const uglify = require('gulp-uglify')
const cssmin = require('gulp-cssmin')
const sass = require('gulp-sass')
const rename = require('gulp-rename')
const concat = require('gulp-concat')
const autoprefixer = require('gulp-autoprefixer')
const babel = require('gulp-babel')
const { version } = require('./package.json')
/**
* JSON DATA
*/
let DATA = require('./env.json')
DATA.version = version
const Vendors = {
'scripts': [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/foundation-sites/dist/js/foundation.min.js',
'node_modules/webfontloader/webfontloader.js',
// 'node_modules/jump.js/dist/jump.js',
// 'node_modules/owl.carousel/dist/owl.carousel.min.js',
// 'node_modules/gmaps/gmaps.min.js',
// 'node_modules/approvejs/dist/approve.min.js',
// 'node_modules/lightbox2/dist/js/lightbox.min.js', useful
// 'node_modules/blazy/blazy.min.js', lazy load
],
'styles':[
"node_modules/foundation-sites/dist/css/foundation.min.css",
// 'node_modules/lightbox2/dist/css/lightbox.min.css',
// 'node_modules/owl.carousel/dist/assets/owl.carousel.min.css',
// 'node_modules/font-awesome/css/font-awesome.min.css',
],
}
const paths = {
public: 'public/',
base_pug: 'source/pug',
pug: 'source/pug/*.pug',
js: 'source/js/*.js',
base_scss: 'source/scss/',
scss: 'source/scss/main.scss',
img: 'source/statics/images/**',
fonts: 'source/statics/fonts/**',
serverScripts: 'source/bin/**',
}
gulp.task('copy_server_scripts', () => {
return gulp.src(paths.serverScripts)
.pipe(gulp.dest(paths.public + 'bin'))
})
/**
* Copy vendors statics assets and standalone scripts
*/
gulp.task('copy_vendors_and_statics', () => {
// Copy fonts statics
gulp.src(paths.fonts)
.pipe(gulp.dest( paths.public + 'fonts'))
gulp.src('node_modules/font-awesome/fonts/**')
.pipe(gulp.dest( paths.public + 'fonts'))
// Copy static images
gulp.src(paths.img)
.pipe(gulp.dest( paths.public + 'images'))
// Isolate Gmaps used only on some pages
gulp.src("./node_modules/gmaps/gmaps.min.js")
.pipe(gulp.dest(paths.public + 'js'))
// Lightbox statics
gulp.src("./node_modules/lightbox2/dist/images/**")
.pipe(gulp.dest(paths.public + 'images'))
// Copy .htaccess
gulp.src(path.resolve('./source/.htaccess'))
.pipe(gulp.dest(paths.public))
})
/**
* Compile pug templates
*/
gulp.task('compile_pug_template', () => {
return gulp.src(paths.pug)
.pipe(pug({
locals: DATA
}))
.pipe(gulp.dest(paths.public))
})
/**
* Compile and minify styles
*/
gulp.task('SASS', () => {
return gulp.src(paths.scss)
.pipe(sass())
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest(paths.public + 'css'))
})
/**
* Compile Scripts
*/
gulp.task('user_scripts', () => {
return gulp.src(paths.js)
.pipe(babel({
presets: ['es2015']
}))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(paths.public + 'js'))
})
/**
* Concat & Uglify vendors
*/
gulp.task('concat_minify_scripts', () => {
return gulp.src(Vendors.scripts)
.pipe(concat('vendors.js'))
.pipe(rename({suffix:'.min'}))
.pipe(gulp.dest(paths.public + 'js'))
})
gulp.task('concat_minify_styles', () => {
return gulp.src(Vendors.styles)
.pipe(concat('vendors.css'))
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(paths.public + 'css'))
})
// DEV WATCHER
gulp.task('watch', () => {
gulp.watch(paths.js, ['user_scripts'])
gulp.watch('source/pug/**/*.pug', ['compile_pug_template'])
gulp.watch(paths.base_scss + '**/**', ['SASS'])
gulp.watch(paths.serverScripts, ['copy_server_scripts'])
})
gulp.task('default', ['copy_server_scripts', 'concat_minify_styles', 'concat_minify_scripts', 'copy_vendors_and_statics', 'user_scripts', 'SASS', 'compile_pug_template'])
gulp.task('dev', ['watch'])