RaMemory/gulpfile.js

120 lines
3.5 KiB
JavaScript
Raw Normal View History

2024-02-08 17:35:42 +01:00
'use strict';
2024-02-08 15:32:50 +01:00
const gulp = require('gulp');
const concat = require('gulp-concat');
const cleanCss = require('gulp-clean-css');
const browsersync = require('browser-sync').create();
const uglify = require('gulp-uglify');
const del = require('del');
const htmlmin = require('gulp-htmlmin');
const copy = require('gulp-copy');
2024-02-08 17:35:42 +01:00
const sass = require('gulp-sass')(require('sass'));
2024-02-08 15:32:50 +01:00
2024-02-08 17:35:42 +01:00
gulp.task('build-css', function () {
return gulp.src('src/Scss/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(concat('index.css'))
.pipe(cleanCss())
.pipe(gulp.dest('build/css'));
2024-02-08 15:32:50 +01:00
});
gulp.task('build-js', function () {
2024-02-08 17:35:42 +01:00
return gulp.src(['src/JavaScript/Css.js',
'src/JavaScript/Firework.js',
'src/JavaScript/PWA.js',
'src/JavaScript/Memory.js',
'src/JavaScript/main.js'])
.pipe(concat('index.js'))
.pipe(uglify())
.pipe(gulp.dest('build/js'));
2024-02-08 15:32:50 +01:00
});
gulp.task('build-sw', function () {
return gulp.src(['src/sw.js'])
2024-02-08 17:35:42 +01:00
.pipe(concat('sw.js'))
.pipe(uglify())
.pipe(gulp.dest('build'));
2024-02-08 15:32:50 +01:00
});
gulp.task('minify-html', () => {
2024-02-08 17:35:42 +01:00
return gulp.src('src/index.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('build'));
2024-02-08 15:32:50 +01:00
});
2024-02-08 17:35:42 +01:00
gulp.task('copy-sitemap', function () {
return gulp.src('src/sitemap.xml')
.pipe(gulp.dest('build'));
2024-02-08 15:32:50 +01:00
});
2024-02-08 17:35:42 +01:00
gulp.task('copy-robots', function () {
return gulp.src('src/robots.txt')
.pipe(gulp.dest('build'));
2024-02-08 15:32:50 +01:00
});
2024-02-08 17:35:42 +01:00
gulp.task('copy-media', function () {
return gulp.src('src/media/*')
.pipe(gulp.dest('build/media'));
2024-02-08 15:32:50 +01:00
});
2024-02-08 17:35:42 +01:00
gulp.task('copy-data', function () {
return gulp.src('src/config/*.json')
.pipe(gulp.dest('build/config'));
2024-02-08 15:32:50 +01:00
});
2024-02-08 17:35:42 +01:00
gulp.task('copy-fonts', function () {
return gulp.src('src/fonts/*')
.pipe(gulp.dest('build/fonts'));
2024-02-08 15:32:50 +01:00
});
2024-02-08 17:35:42 +01:00
gulp.task('copy-favicon', function () {
return gulp.src('src/favicon/*')
.pipe(gulp.dest('build/favicon'));
2024-02-08 15:32:50 +01:00
});
2024-02-08 17:35:42 +01:00
gulp.task('copy-favicon-maskable', function () {
return gulp.src('src/favicon/maskable/*')
.pipe(gulp.dest('build/favicon/maskable'));
2024-02-08 15:32:50 +01:00
});
gulp.task('clean', async () => {
2024-02-08 17:35:42 +01:00
return del.sync('build');
2024-02-08 15:32:50 +01:00
});
2024-02-08 17:35:42 +01:00
2024-02-08 15:32:50 +01:00
gulp.task("clean build", (cb) => {
return gulp.series('clean',
2024-02-08 17:35:42 +01:00
'build-css', 'build-js', 'build-sw', 'minify-html',
'copy-media', 'copy-data', 'copy-favicon', 'copy-favicon-maskable', 'copy-fonts', 'copy-robots', 'copy-sitemap'
)(cb);
2024-02-08 15:32:50 +01:00
});
gulp.task("session-start", (cb) => {
2024-02-08 17:35:42 +01:00
return gulp.series('clean',
'build-css', 'build-js', 'build-sw', 'minify-html',
'copy-media', 'copy-data', 'copy-favicon', 'copy-favicon-maskable', 'copy-fonts', 'copy-robots', 'copy-sitemap'
)(cb);
2024-02-08 15:32:50 +01:00
});
gulp.task("build", (cb) => {
2024-02-08 17:35:42 +01:00
return gulp.series(
'build-css', 'build-js', 'build-sw', 'minify-html',
'copy-media', 'copy-data', 'copy-favicon', 'copy-favicon-maskable', 'copy-fonts', 'copy-robots', 'copy-sitemap'
)(cb);
2024-02-08 15:32:50 +01:00
});
// static server and watching CSS/JS/HTML files for changes
gulp.task("server", (done) => {
2024-02-08 17:35:42 +01:00
browsersync.init({
server: './build',
directory: true
});
// Watch for file changes
gulp.watch('./src/Scss/*.scss', gulp.series('session-start'), browsersync.reload);
gulp.watch('./src/JavaScript/*.js', gulp.series('session-start'), browsersync.reload);
gulp.watch('./src/*.html', gulp.series('session-start'), browsersync.reload);
2024-02-08 15:32:50 +01:00
});
gulp.task('default', gulp.series('session-start'));