I am creating a ReactJS application using the create-Reaction-app utility. How can I configure it to use a file that the service employee will contain?
EDIT : From the Javascript side, everything is clear to me, add the registration to my index.js:
if ('serviceWorker' in navigator) { navigator.serviceWorker.register('./service_workers/sw.js') .then(function(registration) {
Then my configuration in my work service file (which for me is in service_wokers / sw.js):
self.addEventListener('install', function(event) {//my code here...}); self.addEventListener('activate', function(event) {//my code here...}); self.addEventListener('fetch', function(event) {//my code here...});
When I run this, the console shows: ServiceWorker registration error: DOMException: failed to register ServiceWorker: invalid HTTP response code (404) was received when receiving the script.
The file is missing since I am not setting up Webpack for this. So I'm trying to copy the sw.js file with the output with:
test: /\.(js)$/, loader: "file?name=[path][name].[ext]&context=./service_workers", include: '/service_worker'
I think there is no need to say that I am new to Webpack.
reactjs webpack progressive-web-apps service-worker
LilSap
source share