fix(global search): CSS preload killed plugin load

This commit is contained in:
2026-06-27 15:10:24 +09:30
parent 1045d38f47
commit 3213d0ca28
29 changed files with 327 additions and 62 deletions
+8 -1
View File
@@ -15,8 +15,15 @@ export function extensionChunkUrls(): Plugin {
base: "./",
experimental: {
renderBuiltUrl(filename, { hostType, type }) {
const path = filename.replace(/^\//, "");
if (type === "chunk" && hostType === "js") {
const path = filename.replace(/^\//, "");
return {
runtime: `chrome.runtime.getURL(${JSON.stringify(path)})`,
};
}
// Rewrite CSS preloads from JS dynamic imports (content scripts).
// Do not rewrite hostType "css" — extension HTML pages need static hrefs.
if (type === "asset" && hostType === "js" && path.endsWith(".css")) {
return {
runtime: `chrome.runtime.getURL(${JSON.stringify(path)})`,
};
+6 -5
View File
@@ -43,12 +43,13 @@ export default function InlineWorkerDevPlugin(): Plugin {
// Note: Original code had `await fs.readFile(cleanPath, "utf-8");` but `code` wasn't used.
// `esbuild` directly takes `cleanPath` as an entry point.
const result = await build({
entryPoints: [cleanPath], // esbuild uses the file path directly
entryPoints: [cleanPath],
bundle: true,
write: false, // We want the output in memory, not written to disk
platform: "browser", // Target environment for the worker code
format: "iife", // Immediately Invoked Function Expression, suitable for workers
target: "esnext", // Transpile to modern JavaScript
write: false,
platform: "browser",
format: "iife",
target: "esnext",
external: ["webextension-polyfill"],
});
const workerCode = result.outputFiles[0].text;