Programmatic Astro API (experimental)
هذا المحتوى غير متوفر بلغتك بعد.
If you need more control when running Astro, the "astro"
package exports APIs to programmatically run the CLI commands.
These APIs are experimental and their API signature may change. Any updates will be mentioned in the Astro changelog and the information below will always show the current, up-to-date information.
AstroInlineConfig
Section titled AstroInlineConfigThe AstroInlineConfig
type is used by all of the command APIs below. It extends from the user Astro config type:
configFile
Section titled configFileType: string | false
Default: undefined
A custom path to the Astro config file.
If this value is undefined (default) or unset, Astro will search for an astro.config.(js,mjs,ts,mts)
file relative to the root
and load the config file if found.
If a relative path is set, it will resolve based on the root
option.
Set to false
to disable loading any config files.
The inline config passed in this object will take highest priority when merging with the loaded user config.
Type: string
Default: "development"
when running astro dev
, "production"
when running astro build
astro@5.0.0
تجريبي
The mode used when developing or building your site (e.g. "production"
, "testing"
).
This value is passed to Vite using the --mode
flag when the astro build
or astro dev
commands are run to determine the value of import.meta.env.MODE
. This also determines which .env
files are loaded, and therefore the values of astro:env
. See the environment variables page for more details.
To output a development-based build, you can run astro build
with the --devOutput
flag.
logLevel
Section titled logLevelType: "debug" | "info" | "warn" | "error" | "silent"
Default: "info"
The logging level to filter messages logged by Astro.
"debug"
: Log everything, including noisy debugging diagnostics."info"
: Log informational messages, warnings, and errors."warn"
: Log warnings and errors."error"
: Log errors only."silent"
: No logging.
dev()
Section titled dev()Type: (inlineConfig: AstroInlineConfig) => Promise<DevServer>
Similar to astro dev
, it runs Astro’s development server.
DevServer
Section titled DevServeraddress
Section titled addressType: AddressInfo
The address the dev server is listening on.
This property contains the value returned by Node’s net.Server#address()
method.
handle()
Section titled handle()Type: (req: http.IncomingMessage, res: http.ServerResponse<http.IncomingMessage>) => void
A handle for raw Node HTTP requests. You can call handle()
with an http.IncomingMessage
and an http.ServerResponse
instead of sending a request through the network.
watcher
Section titled watcherType: vite.FSWatcher
The Chokidar file watcher as exposed by Vite’s development server.
stop()
Section titled stop()Type: Promise<void>
Stops the development server. This closes all idle connections and stops listening for new connections.
Returns a Promise
that resolves once all pending requests have been fulfilled and all idle connections have been closed.
build()
Section titled build()Type: (inlineConfig: AstroInlineConfig) => Promise<void>
Similar to astro build
, it builds your site for deployment.
preview()
Section titled preview()Type: (inlineConfig: AstroInlineConfig) => Promise<PreviewServer>
Similar to astro preview
, it starts a local server to serve your build output.
If no adapter is set in the configuration, the preview server will only serve the built static files. If an adapter is set in the configuration, the preview server is provided by the adapter. Adapters are not required to provide a preview server, so this feature may not be available depending on your adapter of choice.
PreviewServer
Section titled PreviewServerType: string
The host where the server is listening for connections.
Adapters are allowed to leave this field unset. The value of host
is implementation-specific.
Type: number
The port where the server is listening for connections.
stop()
Section titled stop()Type: Promise<void>
Asks the preview server to close, stop accepting requests, and drop idle connections.
The returned Promise
resolves when the close request has been sent. This does not mean that the server has closed yet. Use the closed()
method if you need to ensure the server has fully closed.
closed()
Section titled closed()Type: Promise<void>
Returns a Promise
that will resolve once the server is closed and reject if an error happens on the server.
sync()
Section titled sync()Type: (inlineConfig: AstroInlineConfig) => Promise<void>
Similar to astro sync
, it generates TypeScript types for all Astro modules.