-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
150 lines (140 loc) Β· 3.38 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const {
src, dest, parallel, series, watch
} = require('gulp');
const sass = require('gulp-sass'); // if you use sass(scss as default)
const cleancss = require('gulp-clean-css');
const concat = require('gulp-concat');
const browserSync = require('browser-sync').create();
const uglify = require('gulp-uglify');
const autoprefixer = require('gulp-autoprefixer');
const del = require('del');
const imagemin = require('gulp-imagemin');
const newer = require('gulp-newer');
const sourcemaps = require('gulp-sourcemaps');
const fileinclude = require('gulp-file-include');
const webpackStream = require('webpack-stream');
const svgSprite = require('gulp-svg-sprite');
const browsersync = () => {
browserSync.init({
server: { baseDir: 'dest' },
notify: true,
port: 4000,
open: true,
});
};
const styles = () => src('src/styles/style.scss')
.pipe(sourcemaps.init())
.pipe(
sass({
outputStyle: 'compressed',
}).on('error', sass.logError)
)
.pipe(
autoprefixer({
overrideBrowserslist: ['> 3%', 'last 2 versions', 'not dead'],
})
)
.pipe(
cleancss({
level: 2,
sourceMap: true,
})
)
.pipe(concat('style.min.css'))
.pipe(sourcemaps.write('./'))
.pipe(dest('dest'))
.pipe(browserSync.stream());
const scripts = () => src('src/script/index.js')
.pipe(
webpackStream({
mode: 'development',
output: {
filename: 'bundle.min.js',
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
],
},
})
)
.on('error', function (err) {
// eslint-disable-next-line no-console
console.error('WEBPACK ERROR', err);
this.emit('end');
})
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(dest('dest'))
.pipe(browserSync.stream());
const fontPack = () => src('src/fonts/*').pipe(dest('dest/fonts'));
const imgPack = () => src([
'src/assets/*.ico',
'src/assets/*.png',
'src/assets/*.jpeg',
'src/assets/*.jpg',
])
.pipe(newer('dest/img/*'))
.pipe(imagemin())
.pipe(dest('dest/img'));
const svgSprites = () => src('src/assets/*.svg')
.pipe(
svgSprite({
mode: {
stack: {
sprite: '../sprite.svg', // sprite file name
},
},
})
)
.pipe(dest('dest/img'));
const htmlFileInclude = () => src('src/*.html')
.pipe(fileinclude({ prefix: '@@', basepath: '@file' }))
.pipe(dest('dest'));
const clear = () => del('dest/**/*');
const startwatch = () => {
watch('src/scss/**/*.scss', parallel('styles'));
watch('src/script/*.js', parallel('scripts'));
watch('src/assets/*', parallel('imgPack'));
watch(['src/*.html', 'src/parts/*.html'], parallel('htmlFileInclude')).on(
'change',
browserSync.reload
);
};
exports.browsersync = browsersync;
exports.styles = styles;
exports.scripts = scripts;
exports.clear = clear;
exports.fontPack = fontPack;
exports.htmlFileInclude = htmlFileInclude;
exports.imgPack = imgPack;
exports.build = series(
clear,
fontPack,
imgPack,
svgSprites,
htmlFileInclude,
styles,
scripts
);
exports.dev = parallel(
clear,
fontPack,
imgPack,
svgSprites,
htmlFileInclude,
styles,
scripts,
browsersync,
startwatch
);