@@ -16,6 +16,7 @@ const gulp = require('gulp');
1616const del = require ( 'del' ) ;
1717const htmlmin = require ( 'gulp-htmlmin' ) ;
1818const concat = require ( 'gulp-concat' ) ;
19+ const injectPartials = require ( 'gulp-inject-partials' ) ;
1920
2021// load config
2122const CONFIG = require ( './gulpfile.config' ) ;
@@ -42,37 +43,42 @@ function browserSyncReload(done) {
4243}
4344
4445// compile styles specific for DropLoad
45- function dlStyles ( ) {
46- return gulp
47- . src ( CONFIG . styles . src )
48- . pipe ( plumber ( ) )
49- // normal file
50- . pipe ( sourceMaps . init ( ) )
51- . pipe ( gulpSass ( { outputStyle : 'expanded' } ) )
52- . pipe ( gulp . dest ( CONFIG . styles . dist ) )
53- // minified versions
54- . pipe ( rename ( { suffix : '.min' } ) )
55- . pipe ( postCSS ( [ autoprefixer ( [ 'last 2 versions' ] ) , cssNano ( ) ] ) )
56- . pipe ( gulp . dest ( CONFIG . styles . dist ) )
57- // concatenated
58- . pipe ( concat ( 'app.css' ) )
59- . pipe ( gulp . dest ( CONFIG . styles . dist ) )
60- . pipe ( browserSync . stream ( ) ) ;
46+ function compileStyles ( ) {
47+ return (
48+ gulp
49+ . src ( CONFIG . styles . src )
50+ . pipe ( plumber ( ) )
51+ // normal file
52+ . pipe ( sourceMaps . init ( ) )
53+ . pipe ( gulpSass ( { outputStyle : 'expanded' } ) )
54+ . pipe ( gulp . dest ( CONFIG . styles . dist ) )
55+ // minified versions
56+ . pipe ( rename ( { suffix : '.min' } ) )
57+ . pipe ( postCSS ( [ autoprefixer ( [ 'last 2 versions' ] ) , cssNano ( ) ] ) )
58+ . pipe ( gulp . dest ( CONFIG . styles . dist ) )
59+ // concatenated
60+ . pipe ( concat ( 'app.css' ) )
61+ . pipe ( gulp . dest ( CONFIG . styles . dist ) )
62+ . pipe ( browserSync . stream ( ) )
63+ ) ;
6164}
6265
6366// generate images
6467function copyImages ( ) {
65- return gulp . src ( CONFIG . images . src )
66- . pipe ( changed ( CONFIG . images . dist ) )
67- . pipe ( gulp . dest ( CONFIG . images . dist ) )
68- . pipe ( imagemin ( {
69- optimizationLevel : 5 ,
70- progressive : true ,
71- svgoPlugins : [ { removeViewBox : false } ] ,
72- interlaced : true
73- } ) )
74- . pipe ( rename ( { suffix : '_minified' } ) )
75- . pipe ( gulp . dest ( CONFIG . images . dist ) ) ;
68+ return (
69+ gulp . src ( CONFIG . images . src )
70+ . pipe ( changed ( CONFIG . images . dist ) )
71+ . pipe ( gulp . dest ( CONFIG . images . dist ) )
72+ . pipe ( imagemin ( {
73+ optimizationLevel : 5 ,
74+ progressive : true ,
75+ svgoPlugins : [ { removeViewBox : false } ] ,
76+ interlaced : true
77+ } ) )
78+ . pipe ( rename ( { suffix : '_minified' } ) )
79+ . pipe ( gulp . dest ( CONFIG . images . dist ) )
80+ . pipe ( browserSync . stream ( ) )
81+ ) ;
7682}
7783
7884// generate scripts
@@ -96,21 +102,12 @@ function scripts() {
96102 ) ;
97103}
98104
99-
100- // file watchers
101- function watchFiles ( ) {
102- gulp . watch ( CONFIG . styles . watch , gulp . parallel ( dlStyles ) ) ;
103- gulp . watch ( CONFIG . scripts . watch , gulp . parallel ( scripts ) ) ;
104- gulp . watch ( CONFIG . html . watch , html , browserSyncReload ) ;
105- gulp . watch ( CONFIG . fonts . watch , fonts , browserSyncReload ) ;
106- gulp . watch ( CONFIG . css . watch , copyCss , browserSyncReload ) ;
107- }
108-
109105// copy and minify html
110106function copyHtml ( ) {
111107 return (
112108 gulp
113109 . src ( CONFIG . html . src )
110+ . pipe ( injectPartials ( ) )
114111 . pipe ( gulp . dest ( CONFIG . html . dist ) )
115112 . pipe ( htmlmin ( { collapseWhitespace : true } ) )
116113 . pipe ( rename ( { suffix : '_min' } ) )
@@ -135,11 +132,21 @@ function copyCss() {
135132 gulp
136133 . src ( CONFIG . css . src )
137134 . pipe ( gulp . dest ( CONFIG . css . dist ) )
135+ . pipe ( browserSync . stream ( ) )
138136 ) ;
139137}
140138
139+ // file watchers
140+ function watchFiles ( ) {
141+ gulp . watch ( CONFIG . styles . watch , compileStyles , browserSyncReload ) ;
142+ gulp . watch ( CONFIG . scripts . watch , scripts , browserSyncReload ) ;
143+ gulp . watch ( CONFIG . html . watch , html , browserSyncReload ) ;
144+ gulp . watch ( CONFIG . fonts . watch , fonts , browserSyncReload ) ;
145+ gulp . watch ( CONFIG . css . watch , styles , browserSyncReload ) ;
146+ }
147+
141148const js = gulp . parallel ( scripts ) ;
142- const styles = gulp . parallel ( dlStyles , copyCss ) ;
149+ const styles = gulp . parallel ( compileStyles , copyCss ) ;
143150const images = gulp . parallel ( copyImages ) ;
144151const html = gulp . parallel ( copyHtml ) ;
145152const fonts = gulp . parallel ( copyFonts ) ;
0 commit comments