Skip to content

Commit d561712

Browse files
committed
Fix links to local and external files
1 parent 584738c commit d561712

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ const injectCSSandJSFactory = (
136136
if (type === InjectType.css) {
137137
const parent = pos === Inject.body ? body : head
138138
addNewLine(parent)
139-
parent.appendChild(new HTMLElement('link', {}, `rel="stylesheet" ${cors}href="/${fileName}"`))
139+
parent.appendChild(new HTMLElement('link', {}, `rel="stylesheet" ${cors}href="${fileName}"`))
140140
} else {
141141
const parent = pos === Inject.head ? head : body
142142
addNewLine(parent)
143-
parent.appendChild(new HTMLElement('script', {}, `${typeModule}${cors}src="/${fileName}"`))
143+
parent.appendChild(new HTMLElement('script', {}, `${typeModule}${cors}src="${fileName}"`))
144144
}
145145
}
146146
}
@@ -244,8 +244,9 @@ consider to use the esm format or switch off the option`)
244244
},
245245

246246
generateBundle(_output, bundle) {
247-
const data = this.cache.get<boolean>(Cache.isHTML) ?
248-
template : fs.readFileSync(template).toString()
247+
const data = this.cache.get<boolean>(Cache.isHTML)
248+
? template
249+
: fs.readFileSync(template).toString()
249250

250251
const doc = parse(data) as HTMLElement & {valid: boolean}
251252
if (!doc.valid) {
@@ -324,12 +325,12 @@ consider to use the esm format or switch off the option`)
324325
const {name, ext} = path.parse(fileName)
325326
const injectType = ext.slice(1)
326327
if (name in entries) {
327-
injectCSSandJS(fileName, injectType, inject)
328+
injectCSSandJS('/' + fileName, injectType, inject)
328329
} else if (name in dynamicEntries && (preload as Set<string>).has(dynamicEntries[name])) {
329330
const linkType = extensionToType(injectType)
330331
if (linkType) {
331332
addNewLine(head)
332-
head.appendChild(new HTMLElement('link', {}, `rel="preload" href="${fileName}" as="${linkType}"`))
333+
head.appendChild(new HTMLElement('link', {}, `rel="preload" href="/${fileName}" as="${linkType}"`))
333334
}
334335
}
335336
})

0 commit comments

Comments
 (0)