Skip to content

Commit

Permalink
feat(docs): add service worker cache (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Mar 24, 2020
1 parent db22086 commit a5879b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"scheduler": "^0.15.0",
"semver-regex": "^2.0.0",
"staged-git-files": "^1.1.2",
"sw-precache-webpack-plugin": "^1.0.0",
"ts-import-plugin": "1.6.1",
"ts-jest": "^24.0.2",
"ts-node": "^8.3.0",
Expand Down
4 changes: 4 additions & 0 deletions scripts/doc-renderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react'
import SiteRenderer from 'react-site-renderer'

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js')
}

export default ({ docs }) => {
return (
<SiteRenderer
Expand Down
15 changes: 15 additions & 0 deletions scripts/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path')
const fs = require('fs-extra')
const { command } = require('doc-scripts')
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin')
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
const HEAD_HTML = `
<script>
window.codeSandBoxDependencies = {
Expand Down Expand Up @@ -100,6 +101,20 @@ const createDocs = async () => {
configFile: path.resolve(__dirname, '../tsconfig.json')
})
]
if(env === 'production'){
webpackConfig.plugins.push(
new SWPrecacheWebpackPlugin(
{
cacheId: 'formily-doc-site',
dontCacheBustUrlsMatching: /\.\w{8}\./,
filename: 'service-worker.js',
minify: true,
navigateFallback: 'https://formilyjs.org/index.html',
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
}
)
)
}
return webpackConfig
}
)
Expand Down

0 comments on commit a5879b7

Please sign in to comment.