Skip to content

Commit

Permalink
fix: background.html missing in dev mode (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
samrum committed Feb 10, 2022
1 parent 32009dd commit 1fa4d47
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/devBuilder/devBuilder.ts
Expand Up @@ -2,7 +2,7 @@ import { copy, emptyDir, ensureDir, readFile, writeFile } from "fs-extra";
import path from "path";
import { ResolvedConfig } from "vite";
import { getContentScriptLoaderFile } from "../utils/loader";
import { getOutputFileName } from "../utils/file";
import { getInputFileName, getOutputFileName } from "../utils/file";
import { getVirtualModule } from "../utils/virtualModule";

export default abstract class DevBuilder<
Expand Down Expand Up @@ -69,19 +69,21 @@ export default abstract class DevBuilder<

protected async writeManifestHtmlFiles(htmlFileNames: string[]) {
for (const fileName of htmlFileNames) {
const absoluteFileName = getInputFileName(fileName, this.viteConfig.root);

let content =
getVirtualModule(fileName) ??
(await readFile(fileName, {
getVirtualModule(absoluteFileName) ??
(await readFile(absoluteFileName, {
encoding: "utf-8",
}));

// update root paths
content = content.replace('src="/', `src="${this.hmrServerOrigin}/`);
content = content.replace(/src="\//g, `src="${this.hmrServerOrigin}/`);

// update relative paths
const inputFileDir = path.dirname(fileName);
content = content.replace(
'src="./',
/src="\.\//g,
`src="${this.hmrServerOrigin}/${inputFileDir ? `${inputFileDir}/` : ""}`
);

Expand Down

0 comments on commit 1fa4d47

Please sign in to comment.