Skip to content

Commit

Permalink
fix: build service worker without writing it to FS (#20909)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Jan 27, 2025
1 parent fe29973 commit 7350de9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions flow-server/src/main/resources/vite.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function injectManifestToSWPlugin(): rollup.Plugin {
const { manifestEntries } = await getManifest({
globDirectory: buildOutputFolder,
globPatterns: ['**/*'],
globIgnores: ['**/*.br', 'pwa-icons/**', 'sw.js'],
globIgnores: ['**/*.br', 'pwa-icons/**'],
manifestTransforms: [rewriteManifestIndexHtmlUrl],
maximumFileSizeToCacheInBytes: 100 * 1024 * 1024 // 100mb,
});
Expand All @@ -119,6 +119,7 @@ function injectManifestToSWPlugin(): rollup.Plugin {

function buildSWPlugin(opts: { devMode: boolean }): PluginOption {
let buildConfig: InlineConfig;
let buildOutput: rollup.RollupOutput;
const devMode = opts.devMode;

return {
Expand All @@ -135,6 +136,7 @@ function buildSWPlugin(opts: { devMode: boolean }): PluginOption {
'process.env.NODE_ENV': JSON.stringify(viteConfig.mode),
},
build: {
write: !devMode,
minify: viteConfig.build.minify,
outDir: viteConfig.build.outDir,
sourcemap: viteConfig.command === 'serve' || viteConfig.build.sourcemap,
Expand All @@ -155,7 +157,12 @@ function buildSWPlugin(opts: { devMode: boolean }): PluginOption {
},
async buildStart() {
if (devMode) {
await build(buildConfig);
buildOutput = await build(buildConfig) as rollup.RollupOutput;
}
},
async load(id) {
if (id.endsWith('sw.js')) {
return buildOutput.output[0].code;
}
},
async closeBundle() {
Expand Down

0 comments on commit 7350de9

Please sign in to comment.