2020-11-23 09:57:52 +00:00
|
|
|
const gulp = require("gulp");
|
|
|
|
const { src, dest, series, parallel } = require("gulp");
|
|
|
|
const autoprefixer = require("autoprefixer"),
|
|
|
|
postcss = require("gulp-postcss"),
|
|
|
|
sass = require("gulp-sass"),
|
|
|
|
sourcemaps = require("gulp-sourcemaps"),
|
|
|
|
del = require("del"),
|
|
|
|
webpack = require("webpack-stream"),
|
|
|
|
webpackConfig = require("./webpack.config.js"),
|
|
|
|
modernizr = require("gulp-modernizr"),
|
|
|
|
svgSprite = require("gulp-svg-sprite"),
|
|
|
|
rename = require("gulp-rename"),
|
|
|
|
imagemin = require("gulp-imagemin"),
|
|
|
|
browserSync = require("browser-sync").create();
|
2020-09-16 12:23:28 +00:00
|
|
|
|
|
|
|
// JS TASKS
|
2020-11-23 09:57:52 +00:00
|
|
|
function cleanScripts() {
|
|
|
|
return del("./app/temp/scripts/App.js");
|
2020-09-16 12:23:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 09:57:52 +00:00
|
|
|
function modernizrTask() {
|
|
|
|
return src(["./app/assets/scss/**/*.scss", "./app/assets/js/**/*.js"])
|
|
|
|
.pipe(
|
|
|
|
modernizr({
|
|
|
|
options: ["setClasses"],
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.pipe(dest("./app/assets/temp"));
|
2020-09-16 12:23:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 09:57:52 +00:00
|
|
|
function scriptsTask() {
|
|
|
|
return (
|
|
|
|
src("./app/assets/js/App.js")
|
|
|
|
.pipe(
|
|
|
|
webpack(webpackConfig, null, function (err, stats) {
|
|
|
|
if (err) {
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
// .on('error', function (err) { if(err){ console.log(err.message);} })
|
2021-05-26 08:55:18 +00:00
|
|
|
.pipe(dest("./app/bundle/scripts")) // copy JS in bundle
|
2020-11-23 09:57:52 +00:00
|
|
|
.pipe(browserSync.stream())
|
|
|
|
);
|
2020-09-16 12:23:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 09:57:52 +00:00
|
|
|
function endCleanModernizr() {
|
|
|
|
return del(["./app/assets/temp"]);
|
2020-09-16 12:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SCSS TASKS
|
|
|
|
function scssTask() {
|
2020-11-23 09:57:52 +00:00
|
|
|
return src("./app/assets/scss/**/*.scss")
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(sass().on("error", sass.logError))
|
|
|
|
.pipe(postcss([autoprefixer()]))
|
|
|
|
.pipe(sourcemaps.write("."))
|
2021-05-26 08:55:18 +00:00
|
|
|
.pipe(dest("./app/bundle/styles")) // copy CSS in bundle
|
2020-11-23 09:57:52 +00:00
|
|
|
.pipe(browserSync.stream());
|
2020-09-16 12:23:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 15:43:28 +00:00
|
|
|
// ICONS TASK
|
|
|
|
var config = {
|
2020-11-23 09:57:52 +00:00
|
|
|
mode: {
|
|
|
|
css: {
|
|
|
|
sprite: "sprite.svg",
|
|
|
|
render: {
|
|
|
|
css: {
|
|
|
|
template: "./gulp/templates/sprite.css",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-10-21 15:43:28 +00:00
|
|
|
|
|
|
|
function beginClean() {
|
2020-11-23 09:57:52 +00:00
|
|
|
return del(["./app/temp/sprite", "-/app/assets/media/images/sprites"]);
|
2020-10-21 15:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function createSprite() {
|
2020-11-23 09:57:52 +00:00
|
|
|
return src("./app/assets/media/images/icons/**/*.svg")
|
|
|
|
.pipe(svgSprite(config))
|
|
|
|
.pipe(dest("./app/temp/sprite/"));
|
2020-10-21 15:43:28 +00:00
|
|
|
}
|
2020-09-16 12:23:28 +00:00
|
|
|
|
2020-10-21 15:43:28 +00:00
|
|
|
function copySpriteGraphic() {
|
2020-11-23 09:57:52 +00:00
|
|
|
return src("./app/temp/sprite/css/**/*.svg").pipe(
|
2021-05-26 08:55:18 +00:00
|
|
|
dest("./app/bundle/media/images/sprites") // copy sprites in bundle
|
2020-11-23 09:57:52 +00:00
|
|
|
);
|
2020-10-21 15:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function copySpriteCSS() {
|
2020-11-23 09:57:52 +00:00
|
|
|
return src("./app/temp/sprite/css/*.css")
|
|
|
|
.pipe(rename("_sprite.scss"))
|
|
|
|
.pipe(dest("./app/assets/scss/modules"));
|
2020-10-21 15:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function endClean() {
|
2020-11-23 09:57:52 +00:00
|
|
|
return del("./app/temp/sprite");
|
2020-10-21 15:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WATCH TASK
|
2020-11-23 09:57:52 +00:00
|
|
|
const watch = function () {
|
|
|
|
browserSync.init({
|
|
|
|
notify: false,
|
|
|
|
server: {
|
|
|
|
baseDir: "./app",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
gulp
|
|
|
|
.watch(
|
|
|
|
"./app/assets/scss/**/*.scss",
|
|
|
|
{ usePolling: true },
|
|
|
|
gulp.series(scssTask)
|
|
|
|
)
|
|
|
|
.on("change", browserSync.reload);
|
|
|
|
gulp.watch(
|
|
|
|
"./app/assets/js/**/*.js",
|
|
|
|
{ usePolling: true },
|
|
|
|
gulp.series(cleanScripts, modernizrTask, scriptsTask, endCleanModernizr)
|
|
|
|
);
|
|
|
|
// gulp.watch("./app/assets/images", {usePolling : true}, gulp.series(imagesTask));
|
|
|
|
gulp.watch("./app/*.html").on("change", browserSync.reload);
|
2020-09-16 12:23:28 +00:00
|
|
|
};
|
|
|
|
|
2020-11-02 12:40:06 +00:00
|
|
|
// IMAGE TASK
|
2020-11-23 09:57:52 +00:00
|
|
|
function imagesTask() {
|
|
|
|
return src([
|
|
|
|
"./app/assets/media/images/**/*",
|
|
|
|
"./app/temp/media/images/**/*",
|
|
|
|
"!./app/assets/media/images/icons",
|
|
|
|
"!./app/assets/media/images/icons/**/*",
|
|
|
|
])
|
|
|
|
.pipe(
|
|
|
|
imagemin({
|
|
|
|
progressive: true,
|
|
|
|
interlaced: true,
|
|
|
|
multipass: true,
|
|
|
|
})
|
|
|
|
)
|
2021-05-26 08:55:18 +00:00
|
|
|
.pipe(dest("./app/bundle/media/images"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// FONT TASK
|
|
|
|
function copyFonts() {
|
|
|
|
return src("./app/assets/media/fonts/**/*")
|
|
|
|
.pipe(dest("./app/bundle/media/fonts"));
|
2020-11-02 12:40:06 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 15:43:28 +00:00
|
|
|
exports.watch = watch;
|
2021-05-26 09:53:59 +00:00
|
|
|
exports.images = imagesTask;
|
2020-11-23 09:57:52 +00:00
|
|
|
exports.icons = series(
|
|
|
|
beginClean,
|
|
|
|
createSprite,
|
|
|
|
copySpriteGraphic,
|
|
|
|
copySpriteCSS,
|
|
|
|
endClean
|
|
|
|
);
|
2021-05-26 09:53:59 +00:00
|
|
|
|
2021-05-26 08:55:18 +00:00
|
|
|
|
|
|
|
exports.copyMediaInBundle = series(
|
|
|
|
copySpriteGraphic,
|
|
|
|
copyFonts,
|
|
|
|
imagesTask
|
|
|
|
);
|