구성 가져오기 API 참조
이 astro:config 가상 모듈은 완전하지는 않지만 직렬화 가능하고 타입 안전한 버전의 Astro 구성을 제공합니다. 구성 값의 서로 다른 하위 집합에 접근하기 위한 두 개의 하위 모듈 /client 및 /server가 있습니다.
astro:config/server에서 사용 가능한 모든 구성 값에 접근할 수 있습니다. 하지만 클라이언트에서 실행되는 코드의 경우, astro:config/client를 통해 노출된 값만 사용할 수 있습니다. 이는 일부 데이터만 클라이언트에 제공함으로써 정보를 보호합니다.
astro:config/client에서 가져오기
import {
i18n,
trailingSlash,
base,
build,
site,
compressHTML,
} from "astro:config/client";클라이언트 측 코드에는 이 하위 모듈을 사용하세요.
import { trailingSlash } from "astro:config/client";
function addForwardSlash(path) {
if (trailingSlash === "always") {
return path.endsWith("/") ? path : path + "/"
} else {
return path
}
}astro:config/client에서 사용할 수 있는 구성 가져오기에 대해 자세히 알아보세요.
astro:config/server에서 가져오기
import {
i18n,
trailingSlash,
base,
build,
site,
srcDir,
cacheDir,
outDir,
publicDir,
root,
compressHTML,
} from "astro:config/server";이러한 가져오기에는 astro:config/client에서 사용할 수 있는 것은 물론, 클라이언트에 노출하기에 안전하지 않은 파일 시스템 구성에 대한 민감한 정보도 포함됩니다.
서버 측 코드에는 이 하위 모듈을 사용하세요.
import { integration } from "./integration.mjs";
export default defineConfig({
integrations: [
integration(),
]
});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);
// 특정 연산으로 데이터를 생성합니다.
let data = JSON.stringify([]);
writeFileSync(fileURLToPath(file), data, "utf-8");
}
}
}
}astro:config/server에서 사용할 수 있는 구성 가져오기에 대해 자세히 알아보세요.
i18ntrailingSlashbasebuild.formatbuild.clientbuild.serversitesrcDircacheDiroutDirpublicDirrootcompressHTML