-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
188 lines (172 loc) · 4.9 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Require
var gulp = require('gulp');
// Include Plugins
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync');
var uglify = require('gulp-uglify');
var cleanCSS = require('gulp-clean-css');
var stripCssComments = require('gulp-strip-css-comments');
var uncss = require('gulp-uncss');
var rename = require('gulp-rename');
var autoprefixer = require('gulp-autoprefixer');
var critical = require('critical').stream;
var imagemin = require('gulp-imagemin');
var svgstore = require('gulp-svgstore');
var svgmin = require('gulp-svgmin');
var rename = require('gulp-rename');
var size = require('gulp-size');
var sassdoc = require('sassdoc');
var cleanhtml = require('gulp-cleanhtml');
var gulpCopy = require('gulp-copy');
// var path = {
// sass: './assets/scss/**/*.scss',
// js: [
// './background/*.js',
// './content-scripts/*.js',
// './smartLogin/scripts/*.js',
// './smartSaveButton/scripts/*.js',
// './smartSaveMenu/scripts/*.js'
// ],
// img: './assets/img/*',
// html: [
// './smartSaveButton/*.html',
// './smartLogin/*.html',
// './smartSaveMenu/*.html'
// ],
// dist: './dist/',
// js_dist: './assets/js/build/'
// };
// Configuration
var path = {
// sass: './assets/scss/**/*.scss',
js: [
'./smart*/**/*.js',
'./content*/*.js',
'./back*/*.js'
],
img: './assets/img/*',
html: [
'./smart*/**/*.html',
'./content*/*.html',
'./back*/*.html'
],
dist: './dist/',
js_dist: './assets/js/build/'
};
var autoprefixerOptions = {
browsers: ['> 1%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1']
};
var reload = browserSync.reload;
var localConfig = require('./localconfig');
// Static Server + watching scss/html files
gulp.task('serve', function () {
if (localConfig.enableBrowserSync) {
browserSync({
proxy: 'http://' + localConfig.serverName + localConfig.subDirectory
});
}
gulp.watch(path.sass, ['sass']);
gulp.watch(path.html).on('change', reload);
gulp.watch(path.js, ['js-dev']);
//.on('change', function(event) {
// console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
//});
});
// Generate SassDoc + Add Sourcemaps + Autoprefixer
// + cache modified files
// + size the final css filereload on change
// + refresh stream
gulp.task('sass', function () {
return gulp
.src(path.sass)
.pipe(sassdoc())
.pipe(sourcemaps.init())
.pipe(sass({
onError: console.error.bind(console, 'SASS error')
}))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./assets/css/'))
.pipe(size())
.pipe(reload({stream: true}));
});
// Production Sass Task : Compile SASS into CSS + Remove comments
// + Remove unused css + Autoprefixer
// + Rename + Minify + Move to dest folder
gulp.task('sass-prod', function () {
return gulp
.src(path.sass)
.pipe(sass({
onError: console.error.bind(console, 'SASS error')
}))
.pipe(stripCssComments())
// .pipe(uncss({
// html: ['index.html']
// }))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(rename({
suffix: '.min'
}))
.pipe(cleanCSS({debug: true}, function (details) {
console.log(details.name + ' original size : ' + details.stats.originalSize);
console.log(details.name + ' minified size : ' + details.stats.minifiedSize);
}))
.pipe(size())
.pipe(gulp.dest(path.dist));
});
// JS Prod Task = Minimify JS + Rename it + Move it to build/js
// TODO : Copy vendor minified files in build/js
// + Concat files + Rename final file
gulp.task('js-prod', function () {
return gulp
.src(path.js)
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(path.dist));
});
// Concat all the files in js directory to build/all.js
// and reload the page
gulp.task('js-dev', function () {
return gulp
.src(path.js)
.pipe(concat('all.js'))
.pipe(gulp.dest(path.js_dist))
.pipe(reload({stream: true}));
});
// Compress Images
gulp.task('img', function () {
return gulp
.src(path.img)
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}]
}))
.pipe(gulp.dest(path.dist + '/img'));
});
// Sprite all the SVG inside the 'icons' folder
// into a single SVG file in 'icons/dest'
gulp.task('svgstore', function () {
return gulp
.src('assets/icons/*.svg')
.pipe(svgmin())
.pipe(svgstore())
.pipe(rename({baseline: 'sprite'}))
.pipe(gulp.dest('assets/icons/dest'));
});
//copy and compress HTML files
gulp.task('html', function () {
return gulp.src(path.html)
.pipe(cleanhtml())
.pipe(gulp.dest(path.dist));
});
gulp.task('copy', function () {
return gulp.src([
'./manifest.json',
'./icon*/*'
]).pipe(gulp.dest(path.dist))
});
gulp.task('default', ['sass', 'serve'], function () {
});
gulp.task('prod', ['js-prod', 'html', 'copy']);