feat: support rewriting urls
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2023-06-13 02:02:41 +02:00
parent 48dcdefee1
commit 6e50208557
8 changed files with 99 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
import { extname } from "node:path";
import path, { extname } from "node:path";
import type {
Plugin,
@@ -48,6 +48,7 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
const {
publicPath,
transform,
rewriteUrl,
load,
htmlFileNames,
resolve,
@@ -353,7 +354,12 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
htmlContents = htmlContents.replace(htmlImport.placeholder, importResult.code);
}else if(htmlImport.type === 'entryChunk'){
const relPath = posix.relative(dirname(chunk.fileName), importResult.fileName);
htmlContents = htmlContents.replace(htmlImport.placeholder, relPath);
const rootPath = path.posix.join(dirname(chunk.fileName), relPath);
const rewritten = rewriteUrl? await Promise.resolve(rewriteUrl(relPath, {
from: chunk.fileName,
rootPath,
})): relPath;
htmlContents = htmlContents.replace(htmlImport.placeholder, rewritten);
}
}
}