Utility tool to append custom code to ServiceWorker created by Create React App.
It allows to keep the default CRA configuration (no ejecting). It simply appends custom code to the ServiceWorker file created by CRA build scripts. By default, it bundles the code using very basic Webpack+Babel configuration (this can be omitted; see options).
$ npm install cra-append-sw --save
$ cra-append-sw [options] <file>
-s, --skip-compile Skip compilation
-h, --help Output usage information
-e, --env [path] (./.env) Path to environment variables file
-m, --mode [mode] Output mode. If `dev`, it creates `public/<file>` instead of appending the code to `build/service-worker.js`. If `build`, it creates `build/<file>` instead of appending the code to `build/service-worker.js`
In package.json
modify build script to:
"start": "react-scripts build && cra-append-sw --mode dev ./custom-sw.js",
"build": "react-scripts build && cra-append-sw ./custom-sw.js",