Commit 335658be authored by Nikolay Gromov's avatar Nikolay Gromov

Conflict fix

parents 4883c5cc 8b64a1d8
...@@ -11,6 +11,7 @@ const autoprefixer = require("autoprefixer") ...@@ -11,6 +11,7 @@ const autoprefixer = require("autoprefixer")
const mqpacker = require("css-mqpacker") const mqpacker = require("css-mqpacker")
const cleanss = require('gulp-cleancss'); const cleanss = require('gulp-cleancss');
const plumber = require('gulp-plumber');
const notify = require('gulp-notify'); const notify = require('gulp-notify');
const gulpIf = require('gulp-if'); const gulpIf = require('gulp-if');
const debug = require('gulp-debug'); const debug = require('gulp-debug');
...@@ -33,6 +34,7 @@ lists.css.forEach(function(blockPath) { ...@@ -33,6 +34,7 @@ lists.css.forEach(function(blockPath) {
}); });
fs.writeFileSync('./src/scss/style.scss', styleImports); fs.writeFileSync('./src/scss/style.scss', styleImports);
// Определим разработка это или финальная сборка
// Запуск `NODE_ENV=production npm start [задача]` приведет к сборке без sourcemaps // Запуск `NODE_ENV=production npm start [задача]` приведет к сборке без sourcemaps
const isDev = !process.env.NODE_ENV || process.env.NODE_ENV == 'dev'; const isDev = !process.env.NODE_ENV || process.env.NODE_ENV == 'dev';
...@@ -59,16 +61,19 @@ gulp.task('style', function () { ...@@ -59,16 +61,19 @@ gulp.task('style', function () {
const sourcemaps = require('gulp-sourcemaps'); const sourcemaps = require('gulp-sourcemaps');
console.log('---------- Компиляция стилей'); console.log('---------- Компиляция стилей');
return gulp.src(dirs.srcPath + 'scss/style.scss') return gulp.src(dirs.srcPath + 'scss/style.scss')
.pipe(plumber({
errorHandler: function(err) {
notify.onError({
title: 'Styles compilation error',
message: err.message
})(err);
this.emit('end');
}
}))
.pipe(gulpIf(isDev, sourcemaps.init())) .pipe(gulpIf(isDev, sourcemaps.init()))
.pipe(debug({title: "Style:"})) .pipe(debug({title: "Style:"}))
.pipe(sass()) .pipe(sass())
.pipe(postcss(postCssPlugins)) .pipe(postcss(postCssPlugins))
.on('error', notify.onError(function(err){
return {
title: 'Styles compilation error',
message: err.message
}
}))
.pipe(gulpIf(!isDev, cleanss())) .pipe(gulpIf(!isDev, cleanss()))
.pipe(rename('style.min.css')) .pipe(rename('style.min.css'))
.pipe(gulpIf(isDev, sourcemaps.write('/'))) .pipe(gulpIf(isDev, sourcemaps.write('/')))
...@@ -78,7 +83,7 @@ gulp.task('style', function () { ...@@ -78,7 +83,7 @@ gulp.task('style', function () {
showTotal: false, showTotal: false,
})) }))
.pipe(gulp.dest(dirs.buildPath + '/css')) .pipe(gulp.dest(dirs.buildPath + '/css'))
.pipe(browserSync.stream()); .pipe(browserSync.stream({match: '**/*.css'}));
}); });
// Копирование добавочных CSS, которые хочется иметь отдельными файлами // Копирование добавочных CSS, которые хочется иметь отдельными файлами
...@@ -91,7 +96,8 @@ gulp.task('copy:css', function() { ...@@ -91,7 +96,8 @@ gulp.task('copy:css', function() {
showFiles: true, showFiles: true,
showTotal: false, showTotal: false,
})) }))
.pipe(gulp.dest(dirs.buildPath + '/css')); .pipe(gulp.dest(dirs.buildPath + '/css'))
.pipe(browserSync.stream());
}); });
// Копирование изображений // Копирование изображений
...@@ -122,7 +128,7 @@ gulp.task('copy:js', function () { ...@@ -122,7 +128,7 @@ gulp.task('copy:js', function () {
// Копирование шрифтов // Копирование шрифтов
gulp.task('copy:fonts', function () { gulp.task('copy:fonts', function () {
console.log('---------- Копирование шрифтов'); console.log('---------- Копирование шрифтов');
return gulp.src(dirs.source + '/fonts/*.{ttf,woff,woff2,eot,svg}') return gulp.src(dirs.srcPath + '/fonts/*.{ttf,woff,woff2,eot,svg}')
.pipe(newer(dirs.buildPath + '/fonts')) // оставить в потоке только изменившиеся файлы .pipe(newer(dirs.buildPath + '/fonts')) // оставить в потоке только изменившиеся файлы
.pipe(size({ .pipe(size({
title: 'Размер', title: 'Размер',
...@@ -133,6 +139,7 @@ gulp.task('copy:fonts', function () { ...@@ -133,6 +139,7 @@ gulp.task('copy:fonts', function () {
}); });
// Сборка SVG-спрайта для блока sprite-svg // Сборка SVG-спрайта для блока sprite-svg
let spritePath = dirs.srcPath + dirs.blocksDirName + '/sprite-svg/svg/';
gulp.task('sprite:svg', function (callback) { gulp.task('sprite:svg', function (callback) {
if((pjson.configProject.blocks['sprite-svg']) !== undefined) { if((pjson.configProject.blocks['sprite-svg']) !== undefined) {
const svgstore = require('gulp-svgstore'); const svgstore = require('gulp-svgstore');
...@@ -196,14 +203,17 @@ gulp.task('js', function (callback) { ...@@ -196,14 +203,17 @@ gulp.task('js', function (callback) {
if(lists.js.length > 0){ if(lists.js.length > 0){
console.log('---------- Обработка JS'); console.log('---------- Обработка JS');
return gulp.src(lists.js) return gulp.src(lists.js)
.pipe(concat('script.min.js')) .pipe(plumber({
.pipe(gulpIf(!isDev, uglify())) errorHandler: function(err) {
.on('error', notify.onError(function(err){ notify.onError({
return { title: 'Javascript concat/uglify error',
title: 'Javascript uglify error', message: err.message
message: err.message })(err);
this.emit('end');
} }
})) }))
.pipe(concat('script.min.js'))
.pipe(gulpIf(!isDev, uglify()))
.pipe(size({ .pipe(size({
title: 'Размер', title: 'Размер',
showFiles: true, showFiles: true,
...@@ -244,11 +254,22 @@ gulp.task('build', function (callback) { ...@@ -244,11 +254,22 @@ gulp.task('build', function (callback) {
gulpSequence( gulpSequence(
'clean', 'clean',
'sprite:svg', 'sprite:svg',
['style', 'copy:css', 'copy:img', 'copy:js', 'copy:fonts'], ['style', 'js', 'copy:css', 'copy:img', 'copy:js', 'copy:fonts'],
'html', 'html',
callback); callback);
}); });
// Отправка в GH pages (ветку gh-pages репозитория)
gulp.task('deploy', function() {
const ghPages = require('gulp-gh-pages');
console.log('---------- Публикация содержимого ./build/ на GH pages');
return gulp.src(dirs.buildPath + '**/*')
.pipe(ghPages());
});
// Задача по умолчанию
gulp.task('default', ['serve']);
// Локальный сервер, слежение // Локальный сервер, слежение
gulp.task('serve', ['build'], function() { gulp.task('serve', ['build'], function() {
browserSync.init({ browserSync.init({
...@@ -260,43 +281,44 @@ gulp.task('serve', ['build'], function() { ...@@ -260,43 +281,44 @@ gulp.task('serve', ['build'], function() {
gulp.watch([ gulp.watch([
dirs.srcPath + dirs.blocksDirName + '/**/*.scss', dirs.srcPath + dirs.blocksDirName + '/**/*.scss',
dirs.srcPath + '/scss/**/*.scss', dirs.srcPath + '/scss/**/*.scss',
], function (event) { ], ['style']);
gulpSequence('style')(function (err) { // Слежение за добавочными стилями
if (err) console.log(err); if(pjson.configProject.copiedCss.length) {
}) gulp.watch(pjson.configProject.copiedCss, ['copy:css']);
}); }
// Слежение за изображениями
if(lists.img.length) {
gulp.watch(lists.img, ['watch:img']);
}
// Слежение за добавочными JS
if(pjson.configProject.copiedJs.length) {
gulp.watch(pjson.configProject.copiedJs, ['watch:copied:js']);
}
// Слежение за шрифтами
gulp.watch(dirs.srcPath + '/fonts/*.{ttf,woff,woff2,eot,svg}', ['watch:fonts']);
// Слежение за SVG для спрайта
if(fileExist(spritePath) !== false) {
gulp.watch(spritePath + '*.svg', ['watch:svg:sprite']);
}
// Слежение за html // Слежение за html
gulp.watch([ gulp.watch([
dirs.srcPath + '/*.html', dirs.srcPath + '/*.html',
dirs.srcPath + '/_include/*.html', dirs.srcPath + '/_include/*.html',
dirs.srcPath + dirs.blocksDirName + '/**/*.html', dirs.srcPath + dirs.blocksDirName + '/**/*.html',
], function (event) { ], ['watch:html']);
gulpSequence('html', browserSync.reload())(function (err) { // Слежение за JS
if (err) console.log(err); if(lists.js.length) {
}) gulp.watch(lists.js, ['watch:js']);
});
// Слежение за изображениями
if(lists.img) {
gulp.watch(lists.img, function (event) {
gulpSequence('copy:img', browserSync.reload())(function (err) {
if (err) console.log(err);
})
});
} }
}); });
// Отправка в GH pages (ветку gh-pages репозитория) // Браузерсинк с 3-м галпом — такой браузерсинк...
// gulp.task('deploy', function() { gulp.task('watch:img', ['copy:img'], reload);
// console.log('---------- Публикация ./build/ на GH pages'); gulp.task('watch:copied:js', ['copy:js'], reload);
// console.log('---------- '+ ghPagesUrl); gulp.task('watch:fonts', ['copy:fonts'], reload);
// return gulp.src('./build/**/*') gulp.task('watch:svg:sprite', ['sprite:svg'], reload);
// .pipe(ghPages()); gulp.task('watch:html', ['html'], reload);
// }); gulp.task('watch:js', ['js'], reload);
// Задача по умолчанию
gulp.task('default',
gulpSequence(['serve'])
);
...@@ -359,3 +381,9 @@ function fileExist(path) { ...@@ -359,3 +381,9 @@ function fileExist(path) {
return !(err && err.code === 'ENOENT'); return !(err && err.code === 'ENOENT');
} }
} }
// Перезагрузка браузера
function reload (done) {
browserSync.reload();
done();
}
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
<p><img src="img/joker.jpg" alt="" width="824" height="460"></p> <p><img src="img/joker.jpg" alt="" width="824" height="460"></p>
<input type="text" value ="qwerty">
@@include('_include/page_bottom.html') @@include('_include/page_bottom.html')
</body> </body>
</html> </html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment