I use Webpack and swPrecache. swPrecache creates the service-worker.js file for me, and now I want to add my own code to the generated file.
I created a Webpack plugin that adds the converted Babel code to the service-worker.js file, for example:
swPrecache.write(filePath, options, (function(err) { // If we want to append an additional file. if (options.appendFile) { var sync = fs.readFile(options.appendFile, (error, code) => { if (error) { throw error; } let transformed = babel.transform(code, options.babelConfig || {}); fs.appendFile(filePath, transformed.code); }); } callback(err); }));
This, however, does not include code to make require() work in the file I am adding. I believe that I need to use Webpack to create the service-worker.js file, but I'm not sure how to do this, perhaps through a custom entry point?
source share