generated from merc1er/gulp-skel
-
Notifications
You must be signed in to change notification settings - Fork 43
/
gulpfile.js
167 lines (135 loc) · 3.96 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const gulp = require('gulp'),
sass = require('gulp-sass')(require('sass')),
del = require('del'),
browserSync = require('browser-sync'),
cleanCSS = require('gulp-clean-css'),
nunjucksRender = require('gulp-nunjucks-render'),
htmlmin = require('gulp-htmlmin'),
data = require('gulp-data'),
i18n = require('gulp-html-i18n'),
concat = require('gulp-concat'),
terser = require('gulp-terser'),
reload = browserSync.reload;
// TASKS
gulp.task('clean', function(done){
// Deletes all files from dist/ and dist-lang/
del.sync('dist/', {force: true});
del.sync('dist-lang/', {force: true});
done()
});
// Internationalization
gulp.task('i18n', function(){
return gulp.src('dist-lang/**/*.html')
.pipe(i18n({
langDir: 'lang', // takes translations from /lang/
createLangDirs: true,
defaultLang: '_',
fallback: '_',
delimiters: ['$(',')$'] // to avoid conflicts with Nunjucks
}))
.pipe(gulp.dest('dist'));
});
// Nunjucks
gulp.task('nunjucks', function() {
// Gets all .html files in pages
return gulp.src('app/**/*.html')
// Adds data from exchanges.json
.pipe(data(function() {
return require('./app/data/exchanges.json')
}))
// Adds data from chips.json
.pipe(data(function() {
return require('./app/data/chips.json')
}))
// Renders template with nunjucks
.pipe(nunjucksRender({
path: ['app/templates/']
}))
.pipe(htmlmin({ // minify HTML
collapseWhitespace: true,
removeComments: true
}))
// Outputs files in dist folder
.pipe(gulp.dest('dist-lang'))
});
// Compile Sass
gulp.task('sass', function(){
return gulp.src('scss/style.scss')
.pipe(sass()) // Compiles styles.scss to css
.pipe(cleanCSS({compatibility: 'ie9'})) // Minifies CSS
.pipe(gulp.dest('app/static/css'))
.pipe(reload({
stream: true
}))
});
// Concat JavaScript
gulp.task('js', function() {
const files = [
'node_modules/jquery/dist/jquery.slim.min.js',
'node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
'node_modules/moveto/dist/moveTo.min.js',
'js/*.js'
];
return gulp.src(files)
.pipe(concat('scripts.js'))
// Minify JS
.pipe(terser())
.pipe(gulp.dest('dist/static/js/'));
});
// Copy all static files
gulp.task('copy-static', function(done){
// Copy _redirects
gulp.src('_redirects').pipe(gulp.dest('dist/'));
// Copy special files to dist/
gulp.src('app/special/*').pipe(gulp.dest('dist/'));
// Copy static files
gulp.src('app/static/**/*.*', {base: './app/static/'})
.pipe(gulp.dest('dist/static/'));
// Copy independant JavaScript files
gulp.src('node_modules/bchaddrjs/dist/bchaddrjs-0.4.9.min.js')
.pipe(gulp.dest('dist/static/js/'));
gulp.src('node_modules/qrcode/build/qrcode.min.js')
.pipe(gulp.dest('dist/static/js/'));
gulp.src('node_modules/qrcode/build/qrcode.min.js.map')
.pipe(gulp.dest('dist/static/js/'));
done();
});
gulp.task('reload', function(done){
reload();
done();
});
// Watch for changes
gulp.task('watch', function(done){
// Watch HTML pages
gulp.watch('app/**/*', gulp.series('nunjucks', 'i18n',
'copy-static', 'reload'));
// Watch SCSS files
gulp.watch('scss/**/*.scss', gulp.series('sass', 'copy-static'));
// Watch static files
gulp.watch('app/static/**/*.*', gulp.series('copy-static',
'reload'));
// Watch JS files
gulp.watch('js/*.js', gulp.series('js', 'reload'));
// Watch translations
gulp.watch('lang/**/*.yaml', gulp.series('i18n', 'reload'));
done();
});
// Starts browserSync
gulp.task('serve', function(done){
browserSync({
server: {
baseDir: './dist',
index: "index.html",
serveStaticOptions: {
extensions: ['html']
}
}
});
done();
});
// Default task
gulp.task('default', gulp.series('clean', 'sass', 'nunjucks', 'i18n',
'copy-static', 'js', 'serve', 'watch'));
// Deployment task
gulp.task('build', gulp.series('clean', 'sass', 'nunjucks', 'i18n',
'copy-static', 'js'));