@@ -66,27 +66,41 @@ function updateIndexFile(options: PwaOptions): Rule {
66
66
const lines = content . split ( '\n' ) ;
67
67
let closingHeadTagLineIndex = - 1 ;
68
68
let closingHeadTagLine = '' ;
69
- lines . forEach ( ( line , index ) => {
69
+ let closingBodyTagLineIndex = - 1 ;
70
+ let closingBodyTagLine = '' ;
71
+ lines . forEach ( ( line : string , index : number ) => {
70
72
if ( / < \/ h e a d > / . test ( line ) && closingHeadTagLineIndex === - 1 ) {
71
73
closingHeadTagLine = line ;
72
74
closingHeadTagLineIndex = index ;
73
75
}
76
+
77
+ if ( / < \/ b o d y > / . test ( line ) && closingBodyTagLineIndex === - 1 ) {
78
+ closingBodyTagLine = line ;
79
+ closingBodyTagLineIndex = index ;
80
+ }
74
81
} ) ;
75
82
76
- const indent = getIndent ( closingHeadTagLine ) + ' ' ;
77
- const itemsToAdd = [
83
+ const headTagIndent = getIndent ( closingHeadTagLine ) + ' ' ;
84
+ const itemsToAddToHead = [
78
85
'<link rel="manifest" href="manifest.json">' ,
79
86
'<meta name="theme-color" content="#1976d2">' ,
80
87
] ;
81
88
82
- const textToInsert = itemsToAdd
83
- . map ( text => indent + text )
89
+ const textToInsertIntoHead = itemsToAddToHead
90
+ . map ( text => headTagIndent + text )
84
91
. join ( '\n' ) ;
85
92
93
+ const bodyTagIndent = getIndent ( closingBodyTagLine ) + ' ' ;
94
+ const itemsToAddToBody = '<noscript>Please enable Javascript to continue using this application.</noscript>'
95
+
96
+ const textToInsertIntoBody = bodyTagIndent + itemsToAddToBody ;
97
+
86
98
const updatedIndex = [
87
99
...lines . slice ( 0 , closingHeadTagLineIndex ) ,
88
- textToInsert ,
89
- ...lines . slice ( closingHeadTagLineIndex ) ,
100
+ textToInsertIntoHead ,
101
+ ...lines . slice ( closingHeadTagLineIndex , closingBodyTagLineIndex ) ,
102
+ textToInsertIntoBody ,
103
+ ...lines . slice ( closingBodyTagLineIndex ) ,
90
104
] . join ( '\n' ) ;
91
105
92
106
host . overwrite ( path , updatedIndex ) ;
0 commit comments