full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -1,4 +1,4 @@
import { normalizePath } from "vite";
import { defaultClientConditions, defaultServerConditions, normalizePath } from "vite";
import { hasSpecialQueries, normalizeFilename } from "../vite-plugin-utils/index.js";
import { compileAstro } from "./compile.js";
import { handleHotUpdate } from "./hmr.js";
@@ -13,10 +13,22 @@ function astro({ settings, logger }) {
let astroFileToCompileMetadata = /* @__PURE__ */ new Map();
const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
const isBrowserPath = (path) => path.startsWith(srcRootWeb) && srcRootWeb !== "/";
const notAstroComponent = (component) => !component.resolvedPath.endsWith(".astro");
const prePlugin = {
name: "astro:build",
enforce: "pre",
// run transforms before other plugins can
async configEnvironment(name, viteConfig, opts) {
viteConfig.resolve ??= {};
if (viteConfig.resolve.conditions == null) {
if (viteConfig.consumer === "client" || name === "client" || opts.isSsrTargetWebworker) {
viteConfig.resolve.conditions = [...defaultClientConditions];
} else {
viteConfig.resolve.conditions = [...defaultServerConditions];
}
}
viteConfig.resolve.conditions.push("astro");
},
configResolved(viteConfig) {
compile = (code, filename) => {
return compileAstro({
@@ -58,11 +70,6 @@ function astro({ settings, logger }) {
if (server) {
const code = await loadId(server.pluginContainer, filename);
if (code != null) await compile(code, filename);
} else if (config.experimental.contentCollectionCache) {
await this.load({
id: filename,
resolveDependencies: false
});
}
compileMetadata = astroFileToCompileMetadata.get(filename);
}
@@ -83,32 +90,30 @@ function astro({ settings, logger }) {
result.dependencies?.forEach((dep) => this.addWatchFile(dep));
return {
code: result.code,
// This metadata is used by `cssScopeToPlugin` to remove this module from the bundle
// if the `filename` default export (the Astro component) is unused.
// `vite.cssScopeTo` is a Vite feature that allows this CSS to be treeshaken
// if the Astro component's default export is not used
meta: result.isGlobal ? void 0 : {
astroCss: {
cssScopeTo: {
[filename]: ["default"]
}
vite: {
cssScopeTo: [filename, "default"]
}
}
};
}
case "script": {
if (typeof query.index === "undefined") {
throw new Error(`Requests for hoisted scripts must include an index`);
throw new Error(`Requests for scripts must include an index`);
}
if (opts?.ssr) {
return {
code: `/* client hoisted script, empty in SSR: ${id} */`
code: `/* client script, empty in SSR: ${id} */`
};
}
const hoistedScript = compileMetadata.scripts[query.index];
if (!hoistedScript) {
throw new Error(`No hoisted script at index ${query.index}`);
const script = compileMetadata.scripts[query.index];
if (!script) {
throw new Error(`No script at index ${query.index}`);
}
if (hoistedScript.type === "external") {
const src = hoistedScript.src;
if (script.type === "external") {
const src = script.src;
if (src.startsWith("/") && !isBrowserPath(src)) {
const publicDir = config.publicDir.pathname.replace(/\/$/, "").split("/").pop() + "/";
throw new Error(
@@ -128,14 +133,14 @@ File: ${id}`
}
}
};
switch (hoistedScript.type) {
switch (script.type) {
case "inline": {
const { code, map } = hoistedScript;
const { code, map } = script;
result.code = appendSourceMap(code, map);
break;
}
case "external": {
const { src } = hoistedScript;
const { src } = script;
result.code = `import "${src}"`;
break;
}
@@ -153,13 +158,23 @@ File: ${id}`
if (hasSpecialQueries(id)) return;
const parsedId = parseAstroRequest(id);
if (!parsedId.filename.endsWith(".astro") || parsedId.query.astro) {
if (this.environment.name === "client") {
const astroFilename = normalizePath(normalizeFilename(parsedId.filename, config.root));
const compileMetadata = astroFileToCompileMetadata.get(astroFilename);
if (compileMetadata && parsedId.query.type === "style" && parsedId.query.index != null) {
const result = compileMetadata.css[parsedId.query.index];
result.dependencies?.forEach((dep) => this.addWatchFile(dep));
}
}
return;
}
const filename = normalizePath(parsedId.filename);
const transformResult = await compile(source, filename);
const astroMetadata = {
clientOnlyComponents: transformResult.clientOnlyComponents,
hydratedComponents: transformResult.hydratedComponents,
// Remove Astro components that have been mistakenly given client directives
// We'll warn the user about this later, but for now we'll prevent them from breaking the build
clientOnlyComponents: transformResult.clientOnlyComponents.filter(notAstroComponent),
hydratedComponents: transformResult.hydratedComponents.filter(notAstroComponent),
serverComponents: transformResult.serverComponents,
scripts: transformResult.scripts,
containsHead: transformResult.containsHead,