-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
124 lines (109 loc) · 4.58 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
const gulp = require("gulp"),
sass = require("gulp-sass"),
concat = require("gulp-concat"),
watch = require("gulp-watch"),
plumber = require("gulp-plumber"),
uglify = require("gulp-uglify"),
prefix = require("gulp-autoprefixer"),
sourcemaps = require("gulp-sourcemaps"),
notify = require("gulp-notify"),
browserSync = require("browser-sync"),
source = require('vinyl-source-stream'), //creates a vinyl stream from readable stream you get from browserify
streamify = require('gulp-streamify'),
browserify = require("browserify"),
rename = require('gulp-rename'),
cssImport = require('gulp-cssimport'), //Parses a CSS file, finds imports, grabs the content of the linked file and replaces the import statement with it.
fileinclude = require('gulp-file-include');
// -----------------------------------------------------------------------------
const config = {
dest : 'dist',
dest_js : 'dist/assets/js',
dest_css : 'dist/assets/css',
dest_img : 'dist/assets/images',
dest_fonts : 'dist/assets/fonts',
dest_html : 'dist/*.html',
dest_assets : 'assets',
src : 'src',
src_html : 'src/*.html',
src_partials: 'src/**/*.html',
src_sass : 'src/sass/**/*.{scss,css}',
src_js : 'src/js/*.js',
src_img : 'src/images/*.**',
src_fonts : 'src/fonts/*.**'
}
// -----------------------------------------------------------------------------
// SASS TO CSS
// -----------------------------------------------------------------------------
function sass_task(){
return gulp.src(config.src_sass)
.pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
.pipe(sass())
.pipe(cssImport())
.pipe(prefix('last 4 versions'))
.pipe(concat('main.css'))
.pipe(rename('main.min.css'))
.pipe(gulp.dest(config.dest_css))
.pipe(browserSync.reload({stream:true}));
};
// -----------------------------------------------------------------------------
// Fonts
// -----------------------------------------------------------------------------
function fonts_task() {
return gulp.src(config.src_fonts)
.pipe(gulp.dest(config.dest_fonts));
};
// -----------------------------------------------------------------------------
// Browserify
// -----------------------------------------------------------------------------
function browserify_task() {
const bundleStream = browserify('src/js/main.js').bundle()
return bundleStream
.pipe(source('index.js'))
.pipe(streamify(uglify()))
.pipe(rename('bundle.js'))
.pipe(gulp.dest(config.dest_js))
.pipe(browserSync.reload({stream:true}));
};
// -----------------------------------------------------------------------------
// Images
// -----------------------------------------------------------------------------
function images_task() {
return gulp.src(config.src_img)
.pipe(gulp.dest(config.dest_img));
};
// -----------------------------------------------------------------------------
// Fileinclude
// -----------------------------------------------------------------------------
function fileinclude_task() {
return gulp.src(config.src_html)
.pipe(fileinclude({
prefix: '@@',
basepath: config.src+'/includes/'
}))
.pipe(gulp.dest(config.dest));
};
// -----------------------------------------------------------------------------
// Watch
// -----------------------------------------------------------------------------
function watch_task(){
browserSync.init({
server: './dist',
injectChanges: true,
proxy: "",
host: ""
});
gulp.watch(config.src_html, {cwd: './'}, fileinclude_task);
gulp.watch(config.src_partials, {cwd: './'}, fileinclude_task);
gulp.watch(config.src_js, {cwd: './'}, browserify_task);
gulp.watch(config.src_sass, {cwd: './'}, sass_task);
gulp.watch(config.src_img, {cwd: './'}, images_task);
gulp.watch(config.dest_css).on('change',browserSync.reload);
gulp.watch(config.dest_js).on('change',browserSync.reload);
gulp.watch(config.dest_img).on('change',browserSync.reload);
gulp.watch(config.dest_html).on('change',browserSync.reload);
};
// -----------------------------------------------------------------------------
//Default
// -----------------------------------------------------------------------------
gulp.task('default',gulp.series(watch_task));
gulp.task('init',gulp.series(gulp.series(fileinclude_task, browserify_task, sass_task,fonts_task,images_task), watch_task));