-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
134 lines (102 loc) · 3.26 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
'use strict';
var gulp = require('gulp')
var inject = require('gulp-inject')
var sass = require('gulp-sass')
var importCss = require('gulp-import-css')
var autoprefixer = require('gulp-autoprefixer')
var sourcemaps = require('gulp-sourcemaps')
var concat = require('gulp-concat')
var cssmin = require('gulp-cssmin')
var watch = require('gulp-watch')
var swPrecache = require('sw-precache')
var uglify = require('gulp-uglify')
var replace = require('gulp-replace')
gulp.task('version', function () {
var time = new Date().getTime()
return gulp.src(['views/base.html.twig'])
.pipe(replace(/version\s=\s\'\d*\'/g, 'version = \''+time+'\''))
.pipe(gulp.dest('views'));
});
// service worker generator
gulp.task('sw', function(callback) {
var packageJson = require('./package.json');
var bundleUrl = '/public/';
swPrecache.write(
'public/sw.js',
{
cacheId: packageJson.name,
// uncomment if you want to control content caching by yourself or have custom offline page
// importScripts: ['/public/sw-contentCaching.js'],
//runtime caching.
runtimeCaching: [{
// matches googleapis cdn's. Fonts, jquery etc.
urlPattern: /(googleapis|gstatic)/,
handler: 'cacheFirst',
options: {
cache: {
maxEntries: 200,
name: 'googleapis-cache'
}
}
},
{
// matches media content from publisher. Images etc.
urlPattern: /(media)/,
handler: 'cacheFirst',
options: {
cache: {
maxEntries: 50,
name: 'media-cache'
}
}
}
],
//assets precache
staticFileGlobs: ['public/dist/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}','public/img/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}', 'public/fonts/**/*.{svg,eot,ttf,woff}'],
stripPrefixMulti: {
'public/': bundleUrl
}
},
callback
);
});
gulp.task('sass', function(){
return gulp.src('public/dist/style.scss')
.pipe(inject(gulp.src(['public/css/**/*.css', 'public/css/**/*.+(sass|scss)'], {read: false}), {
starttag: '/*injector*/',
endtag: ' /*endinjector*/',
transform: function (filePath, file) {
filePath = filePath.replace('/public/css/','../css/');
return '\n@import \'' + filePath + '\';';
}
})
)
.pipe(sourcemaps.init())
.pipe(sass.sync().on('error', sass.logError))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest("public/dist/"));
});
gulp.task('js',function(){
return gulp.src(['public/js/vendor/*.js','public/js/scripts/*.js'])
.pipe(sourcemaps.init())
.pipe(concat('all.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('public/dist'));
});
gulp.task('cssmin', ['sass'],function(){
return gulp.src('public/dist/style.css')
.pipe(importCss())
.pipe(autoprefixer({ browsers: ['last 2 version'], cascade: false }))
.pipe(cssmin())
.pipe(gulp.dest('public/dist'));
});
gulp.task('jsmin', ['js'],function(){
return gulp.src('public/dist/all.js')
.pipe(uglify())
.pipe(gulp.dest('public/dist'));
});
gulp.task('build', ['sass', 'js', 'cssmin' , 'jsmin','version' ]);
gulp.task('watch', function() {
gulp.watch('public/css/**/*.+(css|sass|scss)', ['sass']);
gulp.watch('public/js/**/*.js', ['js']);
});