Website_jan.su/gulpfile.js

136 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-05-28 12:34:36 +02:00
'use strict';
2020-05-27 20:51:32 +02:00
2020-05-28 12:34:36 +02:00
//------------------------
2020-05-27 20:51:32 +02:00
//:: Initiate npm-modules
2020-05-28 12:34:36 +02:00
2020-05-27 20:51:32 +02:00
const gulp = require('gulp'),
2022-02-14 00:41:20 +01:00
sass = require('gulp-sass')(require('sass')),
2020-05-27 20:51:32 +02:00
concat = require('gulp-concat'),
livereload = require('gulp-livereload'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer'),
cssnano = require('cssnano'),
merge2 = require('merge2'),
rimraf = require('rimraf');
2020-05-28 12:34:36 +02:00
//------------------------
//:: Config parameter
2020-05-27 20:51:32 +02:00
var Config = {
inputDir: '_source/',
outputDir: '_dist/'
}
var SassConfig = {
inputDir: '_source/scss/',
outputDir: '_dist/css/',
options: {
outputStyle: 'expanded'
}
}
2020-05-28 12:34:36 +02:00
//------------------------
2020-05-27 20:51:32 +02:00
//:: Tasks
// compile scss
2020-05-28 12:34:36 +02:00
function scss_addons() {
2020-05-27 20:51:32 +02:00
var onError = function(err) {
notify.onError({
2020-05-28 12:34:36 +02:00
title: 'scss_addons',
subtitle: 'Error!',
message: '❌ <%= error.message %>',
sound: 'Submarine'
2020-05-27 20:51:32 +02:00
})(err);
this.emit('end');
};
return merge2(
gulp.src([
'node_modules/sanitize.css/sanitize.css'
]))
.pipe(concat('addons.css'))
2020-05-28 12:34:36 +02:00
.pipe(postcss([autoprefixer()]))
2020-05-27 20:51:32 +02:00
.pipe(gulp.dest(SassConfig.outputDir))
2020-05-28 12:34:36 +02:00
.pipe(postcss([cssnano()]))
2020-05-27 20:51:32 +02:00
.pipe(rename({suffix: '.min'}))
2020-05-28 12:34:36 +02:00
.pipe(gulp.dest(SassConfig.outputDir))
.pipe(livereload())
.pipe(notify({
title: 'scss_addons',
subtitle: 'Success!',
message: '✅ SCSS compiled',
timeout: '2'
}));
}
2020-05-27 20:51:32 +02:00
2020-05-28 12:34:36 +02:00
function scss_main() {
var onError = function(err) {
notify.onError({
title: 'scss_main',
subtitle: 'Error!',
message: '❌ <%= error.message %>',
sound: 'Submarine'
})(err);
this.emit('end');
};
return gulp
.src(SassConfig.inputDir + '*.scss')
2020-05-27 20:51:32 +02:00
.pipe(concat('styles.css'))
.pipe(plumber({errorHandler: onError}))
.pipe(sass(SassConfig.options).on('error', sass.logError))
2020-05-28 12:34:36 +02:00
.pipe(postcss([autoprefixer()]))
2020-05-27 20:51:32 +02:00
.pipe(gulp.dest(SassConfig.outputDir))
2020-05-28 12:34:36 +02:00
.pipe(postcss([cssnano()]))
2020-05-27 20:51:32 +02:00
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(SassConfig.outputDir))
.pipe(livereload())
.pipe(notify({
2020-05-28 12:34:36 +02:00
title: 'scss_main',
2020-05-27 20:51:32 +02:00
subtitle: 'Success!',
message: '✅ SCSS compiled',
timeout: '2'
}));
};
// Copy those other files
function copy(done) {
2020-05-28 12:34:36 +02:00
gulp.src([Config.inputDir + '**/*.*'])
2020-05-27 20:51:32 +02:00
.pipe(gulp.dest(Config.outputDir))
.pipe(livereload())
done();
};
2020-05-28 12:34:36 +02:00
// Watch for changes
2020-05-27 20:51:32 +02:00
function watch() {
livereload.listen();
2020-05-28 12:34:36 +02:00
gulp.watch(SassConfig.inputDir + '*.scss', scss_main);
2020-05-27 20:51:32 +02:00
gulp.watch(Config.inputDir + '*.html', copy);
};
// delete everything in _dist
function cleanup(cb) {
return rimraf(Config.outputDir + '*', cb)
};
2020-05-28 12:34:36 +02:00
//------------------------
//:: Define tasks
2020-05-27 20:51:32 +02:00
// complex tasks
2020-05-28 12:34:36 +02:00
const build = gulp.series(cleanup, gulp.parallel(copy, scss_addons, scss_main));
2020-05-27 20:51:32 +02:00
// export tasks
2020-05-28 12:34:36 +02:00
exports.scss_main = scss_main;
exports.scss_addons = scss_addons;
2020-05-27 20:51:32 +02:00
exports.copy = copy;
exports.watch = watch;
exports.cleanup = cleanup;
exports.build = build;
exports.default = build;