-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
68 lines (60 loc) · 1.81 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// require
const gulp = require("gulp")
const webpackStream = require("webpack-stream")
const webpack = require("webpack")
const sass = require('gulp-sass')
const pleeease = require('gulp-pleeease')
const plumber = require('gulp-plumber')
const watch = require('gulp-watch')
const notify = require('gulp-notify')
const imagemin = require('gulp-imagemin')
const fileInclude = require('gulp-file-include')
// webpack.config.js
const webpackConfig = require("./webpack.config")
// settings
const imagePath = {
src: './img',
dist: './dist/img'
}
// task
gulp.task("webpack", () => {
return webpackStream(webpackConfig, webpack)
.on('error', function handleError () {
this.emit('end')
})
.pipe(gulp.dest("dist/js"))
})
gulp.task('sass', () => {
return gulp.src('./scss/*.scss')
.pipe(plumber({errorHandler: notify.onError('<%= error.message %>')}))
.pipe(sass({
outputStyle: 'expanded'
}))
.pipe(pleeease({
rem: {rootValue: '10px'},
mqpacker: true,
minifier: {preserveHacks: true, removeAllComments: true},
autoprefixer: ['last 2 version', 'ie >= 11', 'iOS >= 8.1', 'Android >= 4.3'],
out: 'bundle.min.css',
}))
.pipe(gulp.dest('./dist/css'))
})
gulp.task('include', ['sass'], function() {
gulp.src('php/header.php')
.pipe(fileInclude())
.pipe(gulp.dest('./'))
});
gulp.task('optimizeImage', () => {
return gulp.src(imagePath.src + '/**/*')
.pipe(plumber({errorHandler: notify.onError('<%= error.message %>')}))
.pipe(imagemin())
.pipe(gulp.dest(imagePath.dist))
})
// command
gulp.task('default', ['include', 'webpack', 'optimizeImage'], () => {})
gulp.task('watch', () => {
gulp.watch('./js/**/*', ['webpack'])
gulp.watch('./img/*', ['optimizeImage'])
gulp.watch('./scss/**/*', ['include'])
gulp.watch('./php/*.php', ['include'])
})