combine all service-worker scripts into a single file to try and ensure included scripts aren't lost

This commit is contained in:
2024-02-14 20:46:34 -07:00
parent ca70b19831
commit f517b09ed7
8 changed files with 75 additions and 28 deletions

View File

@@ -1,5 +1,6 @@
const { defineConfig } = require("@vue/cli-service");
const { gitDescribeSync } = require("git-describe");
const { exec } = require("child_process");
process.env.VUE_APP_GIT_HASH = gitDescribeSync().hash;
@@ -10,6 +11,23 @@ module.exports = defineConfig({
experiments: {
topLevelAwait: true,
},
plugins: [
{
// Still don't know why this runs three times.
apply: (compiler) => {
compiler.hooks.beforeCompile.tap("BeforeCompile", () => {
// Execute combine-sw.js script
exec("node sw_combine.js", (error, stdout, stderr) => {
if (error || stderr) {
console.error("Service worker files error:", error || stderr);
} else {
console.log("Finished combining service worker files.", stdout);
}
});
});
},
},
],
},
pwa: {
iconPaths: {
@@ -17,7 +35,8 @@ module.exports = defineConfig({
},
workboxPluginMode: "InjectManifest",
workboxOptions: {
swSrc: "./sw_scripts/additional-scripts.js",
// this script will be checked for linting (sw_scripts/* files generate about 1000 linting errors)
swSrc: "./sw_scripts-combined.js",
},
},
});