2020-02-27 12:05:33 -07:00
|
|
|
'use strict';
|
2020-02-27 11:11:35 -07:00
|
|
|
|
|
|
|
const { src, dest, series, parallel } = require('gulp');
|
|
|
|
const del = require('del');
|
2020-02-27 12:05:33 -07:00
|
|
|
const babel = require('gulp-babel');
|
2020-02-27 11:11:35 -07:00
|
|
|
const terser = require('gulp-terser');
|
|
|
|
const cssnano = require('gulp-cssnano');
|
|
|
|
const htmlmin = require('gulp-htmlmin');
|
2020-02-27 12:05:33 -07:00
|
|
|
const imagemin = require('gulp-imagemin');
|
2020-02-27 11:11:35 -07:00
|
|
|
const sourcemaps = require('gulp-sourcemaps');
|
|
|
|
|
|
|
|
// Clean assets
|
|
|
|
function clean() {
|
2020-02-27 12:05:33 -07:00
|
|
|
return del(['dist/']);
|
2020-02-27 11:11:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function javascript() {
|
2020-02-27 12:05:33 -07:00
|
|
|
return src('src/**/*.js', {base: './src/'})
|
2020-02-27 11:11:35 -07:00
|
|
|
.pipe(sourcemaps.init({loadMaps: true}))
|
|
|
|
.pipe(babel({
|
|
|
|
presets: ['@babel/preset-env']
|
|
|
|
}))
|
|
|
|
.pipe(terser({
|
|
|
|
keep_fnames: true,
|
|
|
|
mangle: false
|
|
|
|
}))
|
|
|
|
.pipe(sourcemaps.write('.'))
|
2020-02-27 12:05:33 -07:00
|
|
|
.pipe(dest('dist/'));
|
2020-02-27 11:11:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function css() {
|
2020-02-27 12:05:33 -07:00
|
|
|
return src('src/**/*.css', {base: './src/'})
|
2020-02-27 11:11:35 -07:00
|
|
|
.pipe(sourcemaps.init({loadMaps: true}))
|
|
|
|
.pipe(cssnano())
|
|
|
|
.pipe(sourcemaps.write('.'))
|
2020-02-27 12:05:33 -07:00
|
|
|
.pipe(dest('dist/'));
|
2020-02-27 11:11:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function html() {
|
2020-02-27 12:05:33 -07:00
|
|
|
return src('src/**/*.html', {base: './src/'})
|
2020-02-27 11:11:35 -07:00
|
|
|
.pipe(htmlmin({ collapseWhitespace: true }))
|
2020-02-27 12:05:33 -07:00
|
|
|
.pipe(dest('dist/'));
|
2020-02-27 11:11:35 -07:00
|
|
|
}
|
|
|
|
|
2020-02-27 12:05:33 -07:00
|
|
|
function images() {
|
|
|
|
return src(['src/**/*.png', 'src/**/*.jpg', 'src/**/*.gif', 'src/**/*.svg'], {base: './src/'})
|
|
|
|
.pipe(imagemin())
|
|
|
|
.pipe(dest('dist/'))
|
|
|
|
}
|
|
|
|
|
|
|
|
function copy() {
|
|
|
|
return src(['src/**/*.json', 'src/**/*.ico'], {base: './src/'})
|
|
|
|
.pipe(dest('dist/'))
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.default = series(clean, parallel(javascript, css, html, images, copy))
|