Last active
October 23, 2017 07:39
-
-
Save konratnox/139e2324c3145f7c6b71b89db4bedf8f 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'), | |
watch = require('gulp-watch'), | |
rigger = require('gulp-rigger'), | |
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'), | |
rename = require("gulp-rename"); | |
var path = { | |
src: { | |
style: 'css/src/style.scss', | |
js: 'js/src/scripts.js', | |
img: 'images_prebuild/**/*.*', | |
img_import: 'import_prebuild/**/*.*' | |
}, | |
build: { | |
js: 'js/', | |
style: 'css/', | |
img: 'images/', | |
img_import: 'import/' | |
}, | |
watch: { | |
style: 'css/src/**/*.scss', | |
js: 'js/src/**/*.js', | |
} | |
}; | |
gulp.task('style:build', function () { | |
gulp.src(path.src.style) | |
.pipe(sourcemaps.init()) | |
.pipe(sass()) | |
.pipe(autoprefixer()) | |
.pipe(gcmq()) | |
.pipe(cleanCSS()) | |
.pipe(sourcemaps.write('.')) | |
.pipe(gulp.dest(path.build.style)); | |
}); | |
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 | |
}); | |
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},{removeXMLProcInst: true},{removeTitle: true},{removeDesc: true},{removeUselessDefs : true},{convertTransform: true},{collapseGroups: true},{cleanupIDs: true},{removeUnusedNS: true}] | |
}) | |
])) | |
.pipe(gulp.dest(path.build.img)); //И бросим в prod отпимизированные изображения | |
}); | |
gulp.task('image:build_import', function () { | |
return gulp.src(path.src.img_import) //Выберем наши картинки | |
.pipe(gulp.dest(path.build.img_import)) //Копируем изображения заранее, 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_import)); //И бросим в prod отпимизированные изображения | |
}); | |
gulp.task('watch', function() { | |
gulp.watch([path.watch.js], ['js:build']); | |
gulp.watch([path.watch.style], ['style:build']); | |
}); | |
gulp.task('default', ['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": "main_gulp", | |
"version": "1.0.0", | |
"description": "Main gulp css", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"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" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment