/
lr-ru_gitVerse
/
front
Обзор
Документация
Войти
/
lr-ru_gitVerse
/
front
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
gulpfile.js
162 строки
3 KB
Artem Naumov
init
28 окт 2024, 01:39
28 окт 2024, 01:39
9aa6803
Код
Авторство
О чём код?
const { src, dest, watch, series } = require('gulp'); // general const rename = require('gulp-rename'); const del = require('del'); const babel = require("gulp-babel"); const include = require('gulp-rigger'); const plumber = require('gulp-plumber'); const newer = require('gulp-newer'); const run = require('gulp4-run-sequence'); const server = require('browser-sync').create(); // css const sass = require('gulp-sass')(require('sass')); const bulkSass = require('gulp-sass-bulk-import'); const autoprefixer = require('gulp-autoprefixer'); const cssMinify = require('gulp-csso'); function clean() { return del('build'); } function copy() { return src([ 'source/*.html', 'source/font/**/*.{woff,woff2}', 'source/js/**/*.js', 'source/img/**/*', 'source/video/**/*', 'source/data/**/*' ], { base: 'source' }) .pipe(dest('build')); } function htmlCopy() { return src('source/*.html') .pipe(dest('build')); } function css() { return src('source/styles/style.scss') .pipe(plumber()) .pipe(bulkSass()) .pipe(sass({errLogToConsole: true})) .on('error', catchErr) .pipe(autoprefixer({ cascade: false, overrideBrowserslist: ['> 1%', 'last 10 versions', 'ie 8', 'ie 9', 'Firefox 14'], })) .pipe(dest('build/css')) .pipe(cssMinify()) .pipe(rename('style.min.css')) .pipe(dest('build/css')) .pipe(server.stream()); } //don`t stop, when error func function catchErr(e){ console.log(e); this.emit('end'); } //to start babel transpiling run "npm runBabel" command in terminal function runBabel() { console.log('Running runBabel task...'); return src('build/js/script.js') // Assuming the compiled 'script.js' file is in 'build/js' folder .pipe(plumber()) .pipe(babel({ presets: ['@babel/preset-env'] })) .pipe(dest('build/js/babel')) // Save the transpiled file to 'build/js/babel' folder .on('end', () => { console.log('runBabel task completed.'); }); } function jsCopy() { return src('source/js/**/*.js') .pipe(newer('build/js')) .pipe(dest('build/js')); } function jsInclude() { return src('source/js/**/*.js') .pipe(plumber()) .pipe(include()) .pipe(dest('build/js')) } function imgCopy() { return src('source/img/**') .pipe(newer('build/img')) .pipe(dest('build/img')); } function serve() { server.init({ server: "build/", notify: false, open: false, cors: true, ui: false }); watch('source/*.html', htmlUpdate); watch('source/styles/**/*.{scss,sass}', css); watch('source/js/**/*.js', jsUpdate); watch('source/img/**/*', imgUpdate); } function htmlUpdate(done) { series(htmlCopy, reload)(done); } function jsUpdate(done) { series(jsCopy, jsInclude, reload)(done); } function imgUpdate(done) { series(imgCopy, reload)(done); } function reload (done) { server.reload(); done(); } exports.clean = clean; exports.copy = copy; exports.htmlCopy = htmlCopy; exports.css = css; exports.jsCopy = jsCopy; exports.jsInclude = jsInclude; exports.runBabel = runBabel; exports.imgCopy = imgCopy; exports.serve = serve; exports.build = function (done) { run( 'clean', 'copy', 'css', 'jsInclude', done ); }; exports.deploy = function () { return src('build/**/*') .pipe(ghPages()); };