-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
86 lines (76 loc) · 2.2 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const gulp = require('gulp');
const plumber = require('gulp-plumber');
const sourcemap = require('gulp-sourcemaps');
const sass = require('gulp-sass');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const server = require('browser-sync').create();
const cleanCSS = require('gulp-clean-css');
const rename = require('gulp-rename');
const del = require('del');
const webpackStream = require('webpack-stream');
const webpackConfig = require('./webpack.config.js');
gulp.task('html', function () {
return gulp.src(['source/html/*.html']).pipe(gulp.dest('build'));
});
gulp.task('css', function () {
return gulp
.src('source/sass/style.scss')
.pipe(plumber())
.pipe(sourcemap.init())
.pipe(
sass({
outputStyle: 'compact'
}).on('error', sass.logError)
)
.pipe(postcss([autoprefixer({ browsers: ['last 2 version'] })]))
.pipe(
cleanCSS(
{
level: 2
},
(details) => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
}
)
)
.pipe(rename('style.min.css'))
.pipe(sourcemap.write('.'))
.pipe(gulp.dest('build/css'))
.pipe(server.stream());
});
gulp.task('js', function () {
return gulp
.src(['source/js/main.js'])
.pipe(webpackStream(webpackConfig))
.pipe(gulp.dest('build/js'));
});
gulp.task('server', function () {
server.init({
server: 'build/',
notify: false,
open: true,
cors: true,
ui: false
});
gulp.watch('source/html/**/*.html', gulp.series('html', 'refresh'));
gulp.watch('source/sass/**/*.{scss,sass}', gulp.series('css', 'refresh'));
gulp.watch('source/js/**/*.js', gulp.series('js', 'refresh'));
});
gulp.task('refresh', function (done) {
server.reload();
done();
});
gulp.task('copy', function () {
return gulp
.src(['source/fonts/**/*.{woff,woff2}', 'source/favicon/*.ico'], {
base: 'source'
})
.pipe(gulp.dest('build'));
});
gulp.task('clean', function () {
return del('build');
});
gulp.task('build', gulp.series('clean', 'copy', 'html', 'css', 'js'));
gulp.task('start', gulp.series('build', 'server'));