-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
131 lines (116 loc) · 2.93 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
// Gulp packages
var gulp = require('gulp'),
gutil = require('gulp-util'),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
browserSync = require('browser-sync').create(),
imagemin = require('gulp-imagemin'),
newer = require('gulp-newer');
//
// Settings
//
var sourceDir = './source';
var destDir = './public/assets';
var templateDir = './craft/templates';
var src = {
jsFiles: sourceDir + '/js/**/*.js',
styleFiles: sourceDir + '/scss/**/*.scss',
htmlFiles: sourceDir + '/**/*.html',
imageFiles: sourceDir + '/img/**/*'
}
var dest = {
jsFolder: destDir + '/js',
styleFolder: destDir + '/css',
htmlFolder: templateDir,
imageFolder: destDir + '/img'
}
// Naming
// name of bundled js file
var bundleJsName = 'bundle.js';
var proxieUrl = 'localhost:8888'; // put your 'mycraft.local' here
//
// Tasks
//
// Default Task run by "$ gulp"
gulp.task('default', ['build', 'serve', 'watch'], function() {
// set enviroment var
return process.env.type = 'development';
});
gulp.task('build', ['jshint', 'build-js', 'build-css', 'copy-html', 'imagemin'], function() {
// set enviroment var
return process.env.type = 'production';
});
//
// JS
//
// jshint config
gulp.task('jshint', function() {
return gulp.src(src.jsFiles)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
// concat js files and conditionaly uglify it
gulp.task('build-js', function() {
return gulp.src(src.jsFiles)
.pipe(sourcemaps.init())
.pipe(concat(bundleJsName))
// condition if (enviroment variable) type equals 'production'
.pipe(gutil.env.type === 'production' ? uglify() : gutil.noop())
.pipe(sourcemaps.write())
.pipe(gulp.dest(dest.jsFolder));
})
//
// Styles
//
// build css out or sass
gulp.task('build-css', function() {
return gulp.src(src.styleFiles)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write())
.pipe(gulp.dest(dest.styleFolder));
});
//
// Templates / HTML
//
// Copy Template to the template Folder
gulp.task('copy-html', function() {
return gulp.src(src.htmlFiles)
.pipe(gulp.dest(dest.htmlFolder));
});
//
// Server
//
// Static server
// ToDo: Test with real Craft Dev
// - script and style injecting
gulp.task('serve', function() {
browserSync.init({
proxy: proxieUrl
});
});
gulp.task('reload', function() {
browserSync.reload();
});
//
// Images
//
// Copy image assets and compress them if they are new
gulp.task('imagemin', function() {
return gulp.src(src.imageFiles)
.pipe(newer(dest.imageFolder))
.pipe(imagemin())
.pipe(gulp.dest(dest.imageFolder))
});
//
// Watch
//
// Defining which files get watched
gulp.task('watch', function() {
gulp.watch(src.jsFiles, ['jshint','build-js', 'reload']);
gulp.watch(src.styleFiles, ['build-css', 'reload']);
gulp.watch(src.htmlFiles, ['copy-html', 'reload']);
gulp.watch(src.imageFiles, ['imagemin', 'reload']);
});