Created
October 11, 2017 07:59
-
-
Save konratnox/69bb257da383ee42d22b482cd78b0945 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var gulp = require('gulp'), | |
rigger = require('gulp-rigger'), | |
browserSync = require("browser-sync"), | |
reload = browserSync.reload, | |
sourcemaps = require('gulp-sourcemaps'), | |
uglify = require('gulp-uglify'), | |
sass = require('gulp-sass'), | |
autoprefixer = require('gulp-autoprefixer'), | |
gcmq = require('gulp-group-css-media-queries'), | |
cleanCSS = require('gulp-clean-css'), | |
imagemin = require('gulp-imagemin'), | |
imageminPngquant = require('imagemin-pngquant'), | |
imageminJpegRecompress = require('imagemin-jpeg-recompress'), | |
watch = require('gulp-watch'), | |
rename = require("gulp-rename"), | |
rimraf = require('rimraf'); | |
var path = { | |
build: { | |
html: 'verstka/build/', | |
js: 'verstka/build/js/', | |
css: 'verstka/build/css/', | |
img: 'verstka/build/img/', | |
fonts: 'verstka/build/fonts/' | |
}, | |
src: { | |
html: 'verstka/src/*.html', //Синтаксис src/*.html говорит gulp что мы хотим взять все файлы с расширением .html | |
js: 'verstka/src/js/main.js', //В стилях и скриптах нам понадобятся только main файлы | |
style: 'verstka/src/style/main.scss', | |
css: 'verstka/src/style/*.css', | |
img: 'verstka/src/img/**/*.*', //Синтаксис img/**/*.* означает - взять все файлы всех расширений из папки и из вложенных каталогов | |
fonts: 'verstka/src/fonts/**/*.*', | |
js_external: 'verstka/src/js_external/**/*.js' | |
}, | |
watch: { //Тут мы укажем, за изменением каких файлов мы хотим наблюдать | |
html: 'verstka/src/**/*.html', | |
js: 'verstka/src/js/**/*.js', | |
style: 'verstka/src/style/**/*.scss', | |
css: 'verstka/src/style/*.css', | |
img: 'verstka/src/img/**/*.*', | |
fonts: 'verstka/src/fonts/**/*.*', | |
js_external: 'verstka/src/js_external/**/*.js' | |
}, | |
clean: './verstka/build' | |
}; | |
var config = { | |
server: { | |
baseDir: "./verstka/build" | |
}, | |
tunnel: false, | |
host: 'localhost', | |
port: 9000, | |
logPrefix: "Frontend_Devil" | |
}; | |
gulp.task('html:build', function () { | |
gulp.src(path.src.html) //Выберем файлы по нужному пути | |
.pipe(rigger()) //Прогоним через rigger | |
.pipe(gulp.dest(path.build.html)) //Выплюнем их в папку build | |
.pipe(reload({stream: true})); //И перезагрузим наш сервер для обновлений | |
}); | |
gulp.task('js:build', function () { | |
gulp.src(path.src.js) //Найдем наш main файл | |
.pipe(rigger()) //Прогоним через rigger | |
.pipe(gulp.dest(path.build.js)) //Выплюнем готовый файл в build | |
.pipe(sourcemaps.init()) //Инициализируем sourcemap | |
.pipe(uglify()) //Сожмем наш js | |
.pipe(rename({suffix: ".min"})) | |
.pipe(sourcemaps.write('.')) //Пропишем карты | |
.pipe(gulp.dest(path.build.js)) //Выплюнем готовый файл в build | |
.pipe(reload({stream: true})); //И перезагрузим сервер | |
}); | |
gulp.task('style:build', function () { | |
gulp.src(path.src.style) //Выберем наш main.scss | |
.pipe(sourcemaps.init()) //То же самое что и с js | |
.pipe(sass()) //Скомпилируем | |
.pipe(autoprefixer()) //Добавим вендорные префиксы | |
.pipe(gcmq()) | |
.pipe(cleanCSS()) | |
// .pipe(sourcemaps.write('.')) //Пропишем карты | |
.pipe(gulp.dest(path.build.css)) //И в build | |
.pipe(reload({stream: true})); | |
}); | |
gulp.task('image:build', function () { | |
return gulp.src(path.src.img) //Выберем наши картинки | |
.pipe(gulp.dest(path.build.img)) //Копируем изображения заранее, imagemin может пропустить парочку ) | |
.pipe(imagemin([ | |
imagemin.gifsicle({interlaced: true}), | |
imageminJpegRecompress({ | |
progressive: true, | |
max: 80, | |
min: 70 | |
}), | |
imageminPngquant({quality: '80'}), | |
imagemin.svgo({plugins: [{removeViewBox: true}]}) | |
])) | |
.pipe(gulp.dest(path.build.img)); //И бросим в prod отпимизированные изображения | |
}); | |
gulp.task('fonts:build', function() { | |
gulp.src(path.src.fonts) | |
.pipe(gulp.dest(path.build.fonts)) | |
}); | |
gulp.task('js_external:build', function () { | |
gulp.src(path.src.js_external) | |
.pipe(uglify()) | |
.pipe(gulp.dest(path.build.js)) | |
}); | |
gulp.task('css:build', function() { | |
gulp.src(path.src.css) | |
.pipe(cleanCSS()) | |
.pipe(gulp.dest(path.build.css)) | |
}); | |
gulp.task('build', [ | |
'html:build', | |
'js:build', | |
'style:build', | |
// 'css:build', | |
'fonts:build', | |
'image:build', | |
// 'js_external:build' | |
]); | |
gulp.task('watch', function(){ | |
watch([path.watch.html], function(event, cb) { | |
gulp.start('html:build'); | |
}); | |
watch([path.watch.style], function(event, cb) { | |
gulp.start('style:build'); | |
}); | |
watch([path.watch.js], function(event, cb) { | |
gulp.start('js:build'); | |
}); | |
watch([path.watch.img], function(event, cb) { | |
gulp.start('image:build'); | |
}); | |
watch([path.watch.fonts], function(event, cb) { | |
gulp.start('fonts:build'); | |
}); | |
watch([path.watch.js_external], function(event, cb) { | |
gulp.start('js_external:build'); | |
}); | |
watch([path.watch.css], function(event, cb) { | |
gulp.start('css:build'); | |
}); | |
}); | |
gulp.task('webserver', function () { | |
browserSync(config); | |
}); | |
gulp.task('clean', function (cb) { | |
rimraf(path.clean, cb); | |
}); | |
gulp.task('default', ['build', 'webserver', 'watch']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "ne_paday.ru", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"browser-sync": "^2.18.8", | |
"gulp": "^3.9.1", | |
"gulp-autoprefixer": "^3.1.1", | |
"gulp-clean-css": "^3.0.4", | |
"gulp-csso": "^3.0.0", | |
"gulp-group-css-media-queries": "^1.2.0", | |
"gulp-imagemin": "^3.2.0", | |
"gulp-rename": "^1.2.2", | |
"gulp-rigger": "^0.5.8", | |
"gulp-sass": "^3.1.0", | |
"gulp-sourcemaps": "^2.5.0", | |
"gulp-uglify": "^2.1.2", | |
"gulp-watch": "^4.3.11", | |
"imagemin-jpeg-recompress": "^5.1.0", | |
"imagemin-pngquant": "^5.0.1", | |
"rimraf": "^2.6.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment