File tree 3 files changed +12
-6
lines changed
built-in-plugins/service-worker
3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " pri" ,
3
- "version" : " 1.0.0-beta25 " ,
3
+ "version" : " 1.0.0-beta26 " ,
4
4
"types" : " src/node/index.ts" ,
5
5
"main" : " built/node/index.js" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import * as _ from 'lodash';
3
3
import * as path from 'path' ;
4
4
import * as prettier from 'prettier' ;
5
5
import { pri } from '../../node' ;
6
- import { ensureEndWithSlash } from '../../utils/functional' ;
6
+ import { ensureEndWithSlash , ensureStartWithSlash } from '../../utils/functional' ;
7
7
import { tempPath } from '../../utils/structor-config' ;
8
8
9
9
export default async ( instance : typeof pri ) => {
@@ -14,10 +14,8 @@ export default async (instance: typeof pri) => {
14
14
instance . projectConfig . useServiceWorker
15
15
? `
16
16
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 ) ) } "})
21
19
}
22
20
`
23
21
: ''
Original file line number Diff line number Diff line change @@ -15,6 +15,14 @@ export function ensureEndWithSlash(str: string) {
15
15
}
16
16
}
17
17
18
+ export function ensureStartWithSlash ( str : string ) {
19
+ if ( str . startsWith ( '/' ) ) {
20
+ return str ;
21
+ } else {
22
+ return '/' + str ;
23
+ }
24
+ }
25
+
18
26
export function ensureStartWithWebpackRelativePoint ( str : string ) {
19
27
if ( str . startsWith ( '/' ) ) {
20
28
throw Error ( `${ str } is an absolute path!` ) ;
You can’t perform that action at this time.
0 commit comments