-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
164 lines (145 loc) · 4.68 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// PLUGIN NAME - must match scss name and js name - check src/js/pluginname.js and src/scss/project/pluginname.scss
var pluginName = 'pluginname';
// UTILITIES
var gulp = require('gulp');
var rename = require("gulp-rename");
var order = require("gulp-order");
var del = require('del');
var vinylPaths = require('vinyl-paths');
var cache = require('gulp-cached');
// CSS
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var cleanCSS = require('gulp-clean-css');
var csscomb = require('gulp-csscomb');
var cssbeautify = require('gulp-cssbeautify');
// HTML
var htmlmin = require('gulp-htmlmin');
var w3cjs = require('gulp-w3cjs');
var sitemap = require('gulp-sitemap');
// JS
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
// IMAGES
var imagemin = require('gulp-imagemin');
// SERVER
var browserSync = require('browser-sync');
var reload = browserSync.reload;
/*
DEVELOPMENT
- create svg sprites, compile scss, validate js and html and start server with BrowserSync
*/
//scss - compile SCSS, uncss it, autoprefix it, comb beautify it and create sourcemaps
gulp.task('scss', function () {
return gulp.src('src/scss/style.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 10 versions', 'IE 9']
}))
.pipe(csscomb())
.pipe(cssbeautify())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('src/css/'))
.pipe(reload({stream: true}));
});
//html - validate HTML with w3cjs
gulp.task('html', function () {
gulp.src('*.html')
.pipe(cache('html-validation'))
.pipe(w3cjs())
.pipe(reload({stream: true}));
});
//jshint - validate JS with jshint
gulp.task('jshint', function () {
return gulp.src('src/js/' + pluginName + '.js')
.pipe(cache('js-hint'))
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(reload({stream: true}));
});
//DEFAULT - run task with: gulp, open server, watch for changes
gulp.task('default', ['scss', 'html', 'jshint'], function () {
browserSync({
server: {
baseDir: './'
},
// Will not attempt to determine your network status, assumes you're ONLINE
online: true
});
gulp.watch('src/scss/**/*.scss', ['scss']);
gulp.watch('*.html', ['html']);
gulp.watch('src/js/**/*.js', ['jshint']);
});
/*
END DEVELOPMENT
*/
/*
BUILD PROCESS
- builds the project in /dist folder
*/
//delete dist files in the stream
gulp.task('clear:dist', function () {
return gulp.src('dist/*', {dot: true})
.pipe(vinylPaths(del));
});
//dist css
gulp.task('dist:css', ['clear:dist'], function () {
return gulp.src('src/scss/project/' + pluginName + '.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 10 versions', 'IE 9']
}))
.pipe(cleanCSS())
.pipe(rename(pluginName + '.min.css'))
.pipe(gulp.dest('dist/'))
});
//dev css
gulp.task('dev:css', ['clear:dist'], function () {
return gulp.src('src/scss/project/' + pluginName + '.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 10 versions', 'IE 9']
}))
.pipe(cssbeautify())
.pipe(gulp.dest('dist/'))
});
//dist js
gulp.task('dist:js', ['clear:dist'], function () {
return gulp.src(['src/js/' + pluginName + '.js'])
.pipe(uglify())
.pipe(rename(pluginName + '.min.js'))
.pipe(gulp.dest('dist/'));
});
//dev js
gulp.task('dev:js', ['clear:dist'], function () {
return gulp.src(['src/js/' + pluginName + '.js'])
.pipe(gulp.dest('dist/'));
});
//compress:images - optimize images [after clearing dist]
gulp.task('compress:images', ['clear:dist'], function () {
return gulp.src('src/images/**/*')
.pipe(imagemin())
.pipe(gulp.dest('src/images/'));
});
//copy jquery
gulp.task('copy:jquery', ['dev:css', 'dist:css', 'dev:js', 'dist:js', 'compress:images'], function () {
return gulp
.src('src/js/jquery.min.js')
.pipe(gulp.dest('dist/'));
});
//copy scss
gulp.task('copy:scss', ['dev:css', 'dist:css', 'dev:js', 'dist:js', 'compress:images'], function () {
return gulp
.src('src/scss/project/' + pluginName + '.scss')
.pipe(gulp.dest('dist/'));
});
//BUILD - run task with: gulp build
gulp.task('build', ['clear:dist', 'dist:css', 'dev:css', 'dist:js', 'dev:js', 'compress:images', 'copy:jquery', 'copy:scss'], function () {
});
/*
END THE BUILD PROCESS
*/