Skip to content

Commit

Permalink
feat!: inlineRegister renamed to injectRegister and default chang…
Browse files Browse the repository at this point in the history
…ed to file

BREAKING CHANGE:
- instead of injecting the register inline with html, it now generate and import the script from `/registerSW.js` by default.
- options `inlineRegister` renamed to `injectRegister`
  • Loading branch information
antfu committed Feb 19, 2021
1 parent a7632bd commit faf83cc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function resolveOptions(options: Partial<VitePWAOptions>, viteConfig: Res
mode = (process['env']['NODE_ENV'] || 'production') as ('production' | 'development'),
srcDir = 'public',
outDir = viteConfig.build.outDir || 'dist',
inlineRegister = true,
injectRegister = 'import',
filename = 'sw.js',
strategies = 'generateSW',
minify = true,
Expand Down Expand Up @@ -68,7 +68,7 @@ export function resolveOptions(options: Partial<VitePWAOptions>, viteConfig: Res
swDest,
srcDir,
outDir,
inlineRegister,
injectRegister,
filename,
strategies,
workbox,
Expand Down
2 changes: 1 addition & 1 deletion src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ navigator.serviceWorker.register('${join(options.basePath, options.filename)}',
}

export function injectServiceWorker(html: string, options: ResolvedVitePWAOptions) {
if (options.inlineRegister) {
if (options.injectRegister === 'inline') {
return html.replace(
'</head>',
`
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function VitePWA(userOptions: Partial<VitePWAOptions> = {}): Plugin {
source: `${JSON.stringify(options.manifest, null, options.minify ? 0 : 2)}\n`,
fileName: FILE_MANIFEST,
}
if (!options.inlineRegister && !existsSync(join(viteConfig.root, 'public', FILE_SW_REGISTER))) {
if (options.injectRegister === 'import' && !existsSync(join(viteConfig.root, 'public', FILE_SW_REGISTER))) {
bundle[FILE_SW_REGISTER] = {
isAsset: true,
type: 'asset',
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export interface VitePWAOptions {
/**
* Inject the service worker register inlined in the index.html
*
* @default true
* @default 'import'
*/
inlineRegister: boolean
injectRegister: 'inline' | 'import' | null
/**
* Minify the generated manifest
*
Expand Down

0 comments on commit faf83cc

Please sign in to comment.