Vendor workbox

This commit is contained in:
Ken-Håvard Lieng 2018-11-08 09:39:32 +01:00
parent 9a5d7f8360
commit 9b6844449d
4 changed files with 343 additions and 32 deletions

File diff suppressed because one or more lines are too long

View File

@ -66,13 +66,13 @@ function fonts() {
function compress() {
return gulp
.src(['dist/!(*.toml|*.json)'])
.src(['dist/**/!(*.dev.js|*.map|*.toml|*.json|*.woff|*.woff2)'])
.pipe(brotli({ quality: 11 }))
.pipe(gulp.dest('dist'));
}
function cleanup() {
return del(['dist/*(*.js|*.css)']);
return del(['dist/**/*(*.js|*.css|*.map)']);
}
function bindata(cb) {

View File

@ -84,6 +84,7 @@ module.exports = {
}),
new InjectManifest({
swSrc: './src/js/sw.js',
importWorkboxFrom: 'local',
globDirectory: './src',
globPatterns: ['font/*.woff2'],
exclude: [

View File

@ -143,23 +143,11 @@ func (d *Dispatch) initFileServer() {
files = append(files, file)
}
fonts, err := assets.AssetDir("font")
if err != nil {
log.Fatal(err)
}
for _, font := range fonts {
p := strings.TrimSuffix(font, ".br")
file := &File{
Path: path.Join("font", p),
Asset: path.Join("font", font),
ContentType: contentTypes[filepath.Ext(p)],
CacheControl: longCacheControl,
Compressed: strings.HasSuffix(font, ".br"),
root, _ := assets.AssetDir("")
for _, asset := range root {
if _, err = assets.AssetDir(asset); err == nil {
loadDir(asset)
}
files = append(files, file)
}
for _, file := range files {
@ -200,6 +188,27 @@ workbox.routing.registerNavigationRoute('/?sw');`)...)
}
}
func loadDir(dirName string) {
dir, err := assets.AssetDir(dirName)
if err != nil {
log.Fatal(err)
}
for _, asset := range dir {
assetName := strings.TrimSuffix(asset, ".br")
file := &File{
Path: path.Join(dirName, assetName),
Asset: path.Join(dirName, asset),
ContentType: contentTypes[filepath.Ext(assetName)],
CacheControl: longCacheControl,
Compressed: strings.HasSuffix(asset, ".br"),
}
files = append(files, file)
}
}
func decompressAsset(data []byte) []byte {
br, err := brotli.NewReader(bytes.NewReader(data), nil)
if err != nil {