镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions apps/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,30 @@ function devCompressionPlugin(): Plugin {
};
}

// A static import cycle between chunks can run a chunk before the values it imports exist,
// which blanks the app at boot. Fail the build instead of shipping it.
function chunkCycleGuardPlugin(): Plugin {
return {
name: "t3code:chunk-cycle-guard",
apply: "build",
generateBundle(_options, bundle) {
const done = new Set<string>();
const visit = (fileName: string, path: string[]) => {
if (done.has(fileName)) return;
const start = path.indexOf(fileName);
if (start !== -1) {
this.error(`Chunk import cycle: ${[...path.slice(start), fileName].join(" -> ")}`);
}
const chunk = bundle[fileName];
if (chunk?.type !== "chunk") return;
for (const imported of chunk.imports) visit(imported, [...path, fileName]);
done.add(fileName);
};
for (const fileName of Object.keys(bundle)) visit(fileName, []);
},
};
}

// Allow Tailnet hosts for sharing; Tailscale-controlled DNS prevents attacker rebinding.
const configuredAllowedHosts = (process.env.T3CODE_DEV_ALLOWED_HOSTS ?? "")
.split(",")
Expand All @@ -242,6 +266,7 @@ export default defineConfig(() => {
assetsInclude: ["**/*.wasm"],
plugins: [
devCompressionPlugin(),
chunkCycleGuardPlugin(),
builtDev
? undefined
: thirdPartyLicensesPlugin({
Expand Down Expand Up @@ -359,21 +384,6 @@ export default defineConfig(() => {
asset.originalFileNames.some((path) => /[/\\]pdfjs-dist[/\\]wasm[/\\]/.test(path))
? `assets/pdfjs-${pdfjsPkg.version}/[name][extname]`
: "assets/[name]-[hash][extname]",
codeSplitting: {
// Preview imports must not fold shared file icons back into main.
groups: [
{
name: "react",
test: /\/node_modules\/(?:react|react-dom|scheduler)\//,
includeDependenciesRecursively: false,
},
{
name: "icons",
test: /\/(?:components\/chat\/PierreEntryIcon\.tsx|pierre-icons\.ts|mediaPreview\.ts)$/,
includeDependenciesRecursively: false,
},
],
},
},
},
},
Expand Down
Loading