File tree Expand file tree Collapse file tree
built-in-plugins/service-worker Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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" : {
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import * as _ from 'lodash';
33import * as path from 'path' ;
44import * as prettier from 'prettier' ;
55import { pri } from '../../node' ;
6- import { ensureEndWithSlash } from '../../utils/functional' ;
6+ import { ensureEndWithSlash , ensureStartWithSlash } from '../../utils/functional' ;
77import { tempPath } from '../../utils/structor-config' ;
88
99export 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 : ''
Original file line number Diff line number Diff 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+
1826export function ensureStartWithWebpackRelativePoint ( str : string ) {
1927 if ( str . startsWith ( '/' ) ) {
2028 throw Error ( `${ str } is an absolute path!` ) ;
You can’t perform that action at this time.
0 commit comments