Skip to content

Commit 86c4a18

Browse files
committed
fix: sw
1 parent 3401f0b commit 86c4a18

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pri",
3-
"version": "1.0.0-beta25",
3+
"version": "1.0.0-beta26",
44
"types": "src/node/index.ts",
55
"main": "built/node/index.js",
66
"scripts": {

src/built-in-plugins/service-worker/index.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as _ from 'lodash';
33
import * as path from 'path';
44
import * as prettier from 'prettier';
55
import { pri } from '../../node';
6-
import { ensureEndWithSlash } from '../../utils/functional';
6+
import { ensureEndWithSlash, ensureStartWithSlash } from '../../utils/functional';
77
import { tempPath } from '../../utils/structor-config';
88

99
export default async (instance: typeof pri) => {
@@ -14,10 +14,8 @@ export default async (instance: typeof pri) => {
1414
instance.projectConfig.useServiceWorker
1515
? `
1616
if (navigator.serviceWorker) {
17-
navigator.serviceWorker.register("${path.join(
18-
instance.projectConfig.baseHref,
19-
'sw.js'
20-
)}", {scope: "${ensureEndWithSlash(instance.projectConfig.baseHref)}"})
17+
navigator.serviceWorker.register('/sw.js'
18+
)}", {scope: "${ensureStartWithSlash(ensureEndWithSlash(instance.projectConfig.baseHref))}"})
2119
}
2220
`
2321
: ''

src/utils/functional.ts

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ export function ensureEndWithSlash(str: string) {
1515
}
1616
}
1717

18+
export function ensureStartWithSlash(str: string) {
19+
if (str.startsWith('/')) {
20+
return str;
21+
} else {
22+
return '/' + str;
23+
}
24+
}
25+
1826
export function ensureStartWithWebpackRelativePoint(str: string) {
1927
if (str.startsWith('/')) {
2028
throw Error(`${str} is an absolute path!`);

0 commit comments

Comments
 (0)