#How to create a starter template

4 messages · Page 1 of 1 (latest)

hasty knoll
#

How do I create my own Astro template (not theme), so I can quicky starts a new project with all my scaffolding present already (with one command)

full acornBOT
#

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

#

The knowledge sources don't contain detailed documentation specifically about creating a custom starter template from scratch. However, based on what is available, here's what I can tell you:

Using a GitHub Repository as a Template

You can use any existing GitHub repository as a template when creating a new Astro project. This means you can:

  1. Set up your scaffolding in a GitHub repository (your custom template).
  2. Start new projects from it using the --template flag with the create astro command:
# npm
npm create astro@latest -- --template <github-username>/<github-repo>

# pnpm
pnpm create astro@latest --template <github-username>/<github-repo>

# yarn
yarn create astro --template <github-username>/<github-repo>

By default, this uses the repository's main branch. To use a different branch, append it like this: <github-username>/<github-repo>#<branch>. [CLI installation flags]

For Publishing a Reusable Component/Integration

If you want to publish a reusable Astro component template to npm, there is a community-supported component template you can bootstrap with:

npm create astro@latest my-new-component-directory -- --template component

[Working with integrations]


#

In summary: The simplest approach to having a one-command project starter with your own scaffolding is to push your template project to GitHub and use --template <github-username>/<github-repo> when running create astro. The knowledge sources do not go into further detail about additional requirements (e.g., specific package.json fields) needed for a repository to work as a template.

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