@@ -64,21 +64,23 @@ function node (state, createEdge) {
6464 var language = res . language
6565 var title = res . title
6666 var body = res . body
67+ var base = state . metadata . opts . base
6768
6869 var hasDynamicScripts = state . scripts . list . buffer . length > 0
6970
7071 var html = head ( body , language )
7172 var d = documentify ( entry , html )
7273 var header = [
7374 viewportTag ( ) ,
74- scriptTag ( { hash : state . scripts . bundle . hash } ) ,
75+ scriptTag ( { hash : state . scripts . bundle . hash , base : base } ) ,
7576 hasDynamicScripts && dynamicScriptsTag ( {
7677 bundleNames : String ( state . scripts . list . buffer ) . split ( ',' ) ,
77- scripts : state . scripts
78+ scripts : state . scripts ,
79+ base : base
7880 } ) ,
7981 preloadTag ( ) ,
80- loadFontsTag ( { fonts : fonts } ) ,
81- manifestTag ( ) ,
82+ loadFontsTag ( { fonts : fonts , base : base } ) ,
83+ manifestTag ( { base : base } ) ,
8284 descriptionTag ( { description : String ( state . manifest . description . buffer ) } ) ,
8385 themeColorTag ( { color : String ( state . manifest . color . buffer ) } ) ,
8486 titleTag ( { title : title } )
@@ -98,7 +100,7 @@ function node (state, createEdge) {
98100 d . transform ( criticalTransform , { css : state . styles . bundle . buffer } )
99101 }
100102
101- d . transform ( addToHead , styleTag ( { hash : state . styles . bundle . hash } ) )
103+ d . transform ( addToHead , styleTag ( { hash : state . styles . bundle . hash , base : base } ) )
102104
103105 function complete ( buf ) { done ( null , buf ) }
104106
@@ -124,7 +126,7 @@ function preloadTag () {
124126function scriptTag ( opts ) {
125127 var hex = opts . hash . toString ( 'hex' ) . slice ( 0 , 16 )
126128 var base64 = 'sha512-' + opts . hash . toString ( 'base64' )
127- var link = `/${ hex } /bundle.js`
129+ var link = `${ opts . base || '' } /${ hex } /bundle.js`
128130 return `<script src="${ link } " defer integrity="${ base64 } "></script>`
129131}
130132
@@ -133,7 +135,7 @@ function dynamicScriptsTag (opts) {
133135 name = name . replace ( / \. j s $ / , '' )
134136 var hash = opts . scripts [ name ] . hash
135137 var hex = hash . toString ( 'hex' ) . slice ( 0 , 16 )
136- var link = `/${ hex } /${ name } .js`
138+ var link = `${ opts . base || '' } /${ hex } /${ name } .js`
137139 return `<link rel="prefetch" href="${ link } ">`
138140 } ) . join ( '' )
139141}
@@ -144,20 +146,20 @@ function dynamicScriptsTag (opts) {
144146// https://twitter.com/yoshuawuyts/status/920794607314759681
145147function styleTag ( opts ) {
146148 var hex = opts . hash . toString ( 'hex' ) . slice ( 0 , 16 )
147- var link = `/${ hex } /bundle.css`
149+ var link = `${ opts . base || '' } /${ hex } /bundle.css`
148150 return `<link rel="preload" as="style" href="${ link } " onload="this.rel='stylesheet'">`
149151}
150152
151153function loadFontsTag ( opts ) {
152154 return opts . fonts . reduce ( function ( html , font ) {
153- if ( ! path . isAbsolute ( font ) ) font = '/' + font
155+ if ( ! path . isAbsolute ( font ) ) font = ( opts . base || '' ) + '/' + font
154156 return html + `<link rel="preload" as="font" crossorigin href="${ font } ">`
155157 } , '' )
156158}
157159
158- function manifestTag ( ) {
160+ function manifestTag ( opts ) {
159161 return `
160- <link rel="manifest" href="/manifest.json">
162+ <link rel="manifest" href="${ opts . base || '' } /manifest.json">
161163 ` . replace ( / \n + / g, '' )
162164}
163165
0 commit comments