#import { dev } from "astro";

4 messages · Page 1 of 1 (latest)

umbral ermine
#

Are there any examples of how to use the custom dev server?

example in the docs is this

import { dev } from "astro";

const devServer = await dev({
root: "./my-project",
});

// Stop the server if needed
await devServer.stop();

glass fernBOT
#

Hi @umbral ermine. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, the Astro documentation provides an example of how to use the custom dev server. Here's the example you provided:

import { dev } from "astro";

const devServer = await dev({
  root: "./my-project",
});

// Stop the server if needed
await devServer.stop();

In this example, the dev function from the astro package is imported. This function is used to start Astro's development server. The dev function takes an AstroInlineConfig object as an argument, which in this case specifies the root directory of the project.

The dev function returns an AstroDevServer object, which is stored in the devServer constant. This object represents the running development server and can be used to control it. For example, you can stop the server by calling the stop method on the devServer object.

Remember, while the Astro server is running in dev mode, you will not be able to run commands in your terminal window. Instead, this pane will give you feedback as you preview your site. You can stop the dev server at any time and return to the command prompt by typing Ctrl + C in the terminal. If your live preview stops working, go back to the terminal and restart the dev server by typing npm run dev source (https://docs.astro.build/en/tutorial/1-setup/2#view-a-preview-of-your-website).

You can also customize the Astro dev server by setting different configurations based on the command run (“dev”, “preview”). Here's an example:

#
{ 
  // Example: Use the function syntax to customize based on command 
  server: ({ command }) => ({ port: command === 'dev' ? 4321 : 4000 })
}

In this example, the server's port is set to 4321 when the dev command is run, and 4000 otherwise source (https://docs.astro.build/en/reference/configuration-reference#server-options).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: