forked from blenderskool/blaze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
161 lines (143 loc) · 3.66 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const htmlmin = require('gulp-htmlmin');
const babel = require('gulp-babel');
const workboxBuild = require('workbox-build');
const rollup = require('gulp-better-rollup');
const svelte = require('rollup-plugin-svelte');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
/**
* Builds the Stylesheets
*/
gulp.task('styles', function() {
return gulp.src('public/scss/**/*.scss')
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(gulp.dest('dist/css'));
});
/**
* Copies the static files
*/
gulp.task('static', function(done) {
function staticAssets(cb) {
gulp.src([
'static/**/*',
'!static/**/*.js',
], {
nodir: true
})
.pipe(gulp.dest('dist'));
cb();
}
function staticJS(cb) {
gulp.src('static/**/*.js')
.pipe(babel())
.pipe(gulp.dest('dist'))
cb();
}
return gulp.parallel(staticAssets, staticJS)(done);
});
/**
* Create Service worker using Workbox
*/
gulp.task('sw', async function() {
await workboxBuild.generateSW({
swDest: './dist/sw.js',
globDirectory: './dist',
globPatterns: ['app.html', 'fonts/*'],
runtimeCaching: [
{
urlPattern: /\.(?:js|css)$/,
handler: 'StaleWhileRevalidate',
},
{
urlPattern: /^https:\/\/fonts\.googleapis\.com/,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'blaze-google-fonts-stylesheets'
}
},
{
urlPattern: /^https:\/\/fonts\.gstatic\.com/,
handler: 'CacheFirst',
options: {
cacheName: 'blaze-google-fonts-webfonts',
cacheableResponse: {
statuses: [0, 200],
},
expiration: {
maxAgeSeconds: 60 * 60 * 24 * 365 // An year
}
},
},
{
// Url pattern excludes images whose names starts with icon
urlPattern: /(?:noise.png)$/,
handler: 'CacheFirst',
options: {
cacheName: 'blaze-images',
expiration: {
maxEntries: 60,
maxAgeSeconds: 60 * 60 * 24 * 30, // 30 Days
}
}
}
],
cacheId: 'blaze',
});
// Further processing
return gulp.src('./dist/sw.js', { base: './' })
.pipe(babel())
.pipe(gulp.dest('./'));
});
/**
* HTML minification
*/
gulp.task('html', function() {
return gulp.src('public/**/*.html')
.pipe(htmlmin({
collapseWhitespace: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
useShortDoctype: true,
removeComments: true
}))
.pipe(gulp.dest('dist'));
});
/**
* Compiling and bundling the Svelte app
*/
gulp.task('svelte', function() {
return gulp.src('public/app.js')
.pipe(rollup({
plugins: [
svelte({
dev: false,
/**
* Bundling the scoped css of components
* Scoped css is not bundled as of now
*/
// css: css => {
// css.write('dist/bundle.css');
// }
}),
resolve({
browser: true,
dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/')
}),
commonjs(),
],
}, 'iife'))
.pipe(babel())
.pipe(gulp.dest('dist/js'));
});
/**
* Building for production
*/
gulp.task('default', gulp.series(gulp.parallel('static', 'styles', 'html', 'svelte'), 'sw'));
/**
* File Watcher during development
*/
gulp.task('dev', gulp.series('default', function watcher() {
return gulp.watch(['public/**/*', 'static/**/*'], gulp.parallel('default'));
}));