-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add precaching Service Worker to exported docs builds (#10267)
* Add service worker to exported docs builds * push forward
- Loading branch information
1 parent
e707ac3
commit bf7feca
Showing
7 changed files
with
215 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import path from 'path'; | ||
import workboxBuild from 'workbox-build'; | ||
|
||
const exportDir = path.join(__dirname, '../export'); | ||
|
||
workboxBuild | ||
.injectManifest({ | ||
swSrc: path.join(__dirname, '../src/sw.js'), | ||
swDest: path.join(exportDir, '/sw.js'), | ||
globDirectory: exportDir, | ||
globPatterns: ['**/*.{js,html}'], | ||
}) | ||
.then(({ count }) => { | ||
console.log('Successfully built service worker'); | ||
console.log(`${count} files were marked for precaching`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* eslint-env serviceworker */ | ||
/* global workbox */ | ||
|
||
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0-beta.0/workbox-sw.js'); | ||
|
||
workbox.core.setCacheNameDetails({ | ||
prefix: 'mui', | ||
}); | ||
|
||
workbox.precaching.precacheAndRoute([]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,43 @@ | ||
{ | ||
"hosting": { | ||
"public": "docs/export" | ||
"public": "docs/export", | ||
"headers": [ | ||
{ | ||
"source": "**", | ||
"headers": [ | ||
{ | ||
"key": "Cache-Control", | ||
"value": "no-cache" | ||
} | ||
] | ||
}, | ||
{ | ||
"source": "**/*.js", | ||
"headers": [ | ||
{ | ||
"key": "Cache-Control", | ||
"value": "public, max-age=31536000" | ||
} | ||
] | ||
}, | ||
{ | ||
"source": "/sw.js", | ||
"headers": [ | ||
{ | ||
"key": "Cache-Control", | ||
"value": "no-cache" | ||
} | ||
] | ||
}, | ||
{ | ||
"source" : "**/*.@(jpg|jpeg|gif|png)", | ||
"headers": [ | ||
{ | ||
"key": "Cache-Control", | ||
"value": "public, max-age=7200" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters