Last active
July 14, 2020 10:16
-
-
Save GautamPanickar/fb4fe6a3bd95c1d9d4e30f7e5fb5f09b to your computer and use it in GitHub Desktop.
Service worker with Google's Workbox for Angular App - config files.
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
{ | |
"compilerOptions": { | |
"typeRoots" : ["./typings"], | |
"module": "esnext", | |
"moduleResolution": "node", | |
"importHelpers": true, | |
"target": "es2015", | |
"lib": [ | |
"esnext", | |
"webworker" | |
] | |
}, | |
"files": ["./service-worker.ts", "./sw-handler.ts"], | |
} |
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
// Webpack configuration used to build the service worker | |
const path = require('path'); | |
const webBuildTargetFolder = path.join(__dirname, '../..', 'dist', 'swtest'); | |
const targetServiceWorkerFilename = 'service-worker.js'; | |
const webpackEntryPath = path.join(__dirname, 'service-worker.ts'); | |
console.log('--------------------------------'); | |
console.log('Webpack Config paths in use:'); | |
console.log('--------------------------------'); | |
console.log('Webpack entry file: ' + webpackEntryPath); | |
console.log('Target folder: ' + webBuildTargetFolder); | |
console.log('Target service worker: ' + targetServiceWorkerFilename); | |
console.log('--------------------------------'); | |
module.exports = { | |
target: 'node', | |
mode: 'production', // Change to 'development' if you want to build it in dev mode,which wont minify the file. | |
entry: { | |
index: webpackEntryPath, | |
}, | |
resolve: { extensions: ['.ts', '.wasm', '.mjs', '.js', '.json'] }, | |
output: { | |
path: webBuildTargetFolder, | |
filename: targetServiceWorkerFilename, | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.ts$/, | |
loader: 'ts-loader', | |
exclude: /node_modules/, | |
options: { | |
onlyCompileBundledFiles: true, | |
}, | |
}, | |
], | |
}, | |
plugins: [], | |
}; |
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
module.exports = { | |
globDirectory: 'dist/swtest/', | |
globPatterns: ['**/*.{css,scss,eot,html,ico,jpg,jpeg,js,json,png,svg,ttf,txt,webmanifest,woff,woff2,webm,xml}'], | |
globFollow: true, | |
globStrict: true, | |
globIgnores: [ | |
`**/*-es5.*.js`, | |
], | |
dontCacheBustURLsMatching: new RegExp('.+.[a-f0-9]{20}..+'), | |
maximumFileSizeToCacheInBytes: 4 * 1024 * 1024, // 4Mb | |
swSrc: 'dist/swtest/service-worker.js', | |
swDest: 'dist/swtest/service-worker.js' | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment