Zum Inhalt springen

Config imports API Reference

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Hinzugefügt in: astro@5.7.0 Neu

This virtual module astro:config exposes a non-exhaustive, serializable, type-safe version of the Astro configuration. There are two submodules for accessing different subsets of your configuration values: /client and /server.

All available config values can be accessed from astro:config/server. However, for code executed on the client, only those values exposed by astro:config/client will be available. This protects your information by only making some data available to the client.

Imports from astro:config/client

Section titled Imports from astro:config/client
import {
i18n,
trailingSlash,
base,
build,
site,
} from "astro:config/client";

Use this submodule for client-side code:

src/utils.js
import { trailingSlash } from "astro:config/client";
function addForwardSlash(path) {
if (trailingSlash === "always") {
return path.endsWith("/") ? path : path + "/"
} else {
return path
}
}

See more about the configuration imports available from astro:config/client:

Imports from astro:config/server

Section titled Imports from astro:config/server
import {
i18n,
trailingSlash,
base,
build,
site,
srcDirc,
cacheDir,
outDir,
publicDir,
root,
} from "astro:config/client";

These imports include everything available from astro:config/client as well as additional sensitive information about your file system configuration that is not safe to expose to the client.

Use this submodule for server side code:

astro.config.mjs
import { integration } from "./integration.mjs";
export default defineConfig({
integrations: [
integration(),
]
});
integration.mjs
import { outDir } from "astro:config/server";
import { writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
export default function() {
return {
name: "internal-integration",
hooks: {
"astro:build:done": () => {
let file = new URL("result.json", outDir);
// generate data from some operation
let data = JSON.stringify([]);
writeFileSync(fileURLToPath(path), data, "utf-8");
}
}
}
}

See more about the configuration imports available from astro:config/server:

Wirke mit Community Sponsor