The web framework that scales with you — Build fast content sites, powerful web applications, dynamic server APIs, and everything in-between ️ Star to support our work!
Find a file
2021-05-05 12:44:31 -05:00
.changeset chore: version packages 2021-05-04 17:16:23 -05:00
.github Attempt to fix CI skipping (#165) 2021-05-03 11:27:21 -06:00
.vscode Split out astro-languageserver and astro-vscode (#173) 2021-05-05 12:44:31 -05:00
assets chore: remove github banner, add to banner to README (#108) 2021-04-16 12:51:30 -05:00
docs Format (#167) 2021-05-03 12:26:10 -06:00
examples chore: version packages 2021-05-04 17:16:23 -05:00
packages 0.0.12 2021-05-05 11:27:55 -04:00
scripts Format (#167) 2021-05-03 12:26:10 -06:00
tools Split out astro-languageserver and astro-vscode (#173) 2021-05-05 12:44:31 -05:00
www chore: version packages 2021-05-04 17:16:23 -05:00
.editorconfig Adds .editorconfig file (#162) 2021-05-03 12:41:39 -05:00
.eslintignore Migrate to yarn monorepo (#157) 2021-04-30 16:33:35 -05:00
.eslintrc.cjs Prettier support for .astro files (#106) 2021-04-21 11:14:44 -05:00
.gitignore fix: monorepo issues (#158) 2021-04-30 16:38:40 -05:00
.nvmrc set node version in nvmrc & engines to lts (#87) 2021-04-13 13:03:26 -04:00
.prettierignore Format (#167) 2021-05-03 12:26:10 -06:00
.prettierrc.json Annoying Lint PR™ (#3) 2021-03-16 12:37:45 -06:00
lerna.json Format (#167) 2021-05-03 12:26:10 -06:00
LICENSE Bring compiler into Astro (#4) 2021-03-16 16:08:11 -04:00
package.json Split out astro-languageserver and astro-vscode (#173) 2021-05-05 12:44:31 -05:00
README.md Format (#167) 2021-05-03 12:26:10 -06:00
tsconfig.base.json Migrate to yarn monorepo (#157) 2021-04-30 16:33:35 -05:00
yarn.lock Split out astro-languageserver and astro-vscode (#173) 2021-05-05 12:44:31 -05:00

Astro

Astro is a fresh but familiar approach to building websites. Astro combines decades of proven performance best practices with the DX improvements of the component-oriented era.

With Astro, you can use your favorite JavaScript framework and automatically ship the bare-minimum amount of JavaScript—by default, it's none at all!

🔧 Setup

# currently "hidden" during private beta
npm init astro@shhhhh ./my-astro-project

# then... cd => install => start
cd ./my-astro-project
npm install
npm start

🚀 Build & Deployment

The default Astro project has the following scripts in the /package.json file:

{
  "scripts": {
    "start": "astro dev .",
    "build": "astro build ."
  }
}

For local development, run:

npm run start

To build for production, run the following command:

npm run build

To deploy your Astro site to production, upload the contents of /dist to your favorite static site host.

🥾 Guides

🚀 Basic Usage

Even though nearly-everything is configurable, we recommend starting out by creating an src/ folder in your project with the following structure:

├── src/
│   ├── components/
│   └── pages/
│       └── index.astro
├── public/
└── package.json
  • src/components/*: where your reusable components go. You can place these anywhere, but we recommend a single folder to keep them organized.
  • src/pages/*: this is a special folder where your routing lives.

🚦 Routing

Routing happens in src/pages/*. Every .astro or .md.astro file in this folder corresponds with a public URL. For example:

Local file Public URL
src/pages/index.astro /index.html
src/pages/post/my-blog-post.md.astro /post/my-blog-post/index.html

🗂 Static Assets

Static assets should be placed in a public/ folder in your project. You can place any images, fonts, files, or global CSS in here you need to reference.

🪨 Generating HTML with Astro

TODO: Astro syntax guide

Dynamic Components

TODO: Astro dynamic components guide

💧 Partial Hydration

By default, Astro outputs zero client-side JS. If you'd like to include an interactive component in the client output, you may use any of the following techniques.

  • <MyComponent /> will render an HTML-only version of MyComponent (default)
  • <MyComponent:load /> will render MyComponent on page load
  • <MyComponent:idle /> will use requestIdleCallback() to render MyComponent as soon as main thread is free
  • <MyComponent:visible /> will use an IntersectionObserver to render MyComponent when the element enters the viewport

⚛️ State Management

Frontend state management depends on your framework of choice. Below is a list of popular frontend state management libraries, and their current support with Astro.

Our goal is to support all popular state management libraries, as long as there is no technical reason that we cannot.

  • React/Preact
    • Redux: Partial Support (Note: You can access a Redux store directly, but full react-redux support requires the ability to set a custom <Provider> wrapper to every component island. Planned.)
    • Recoil: Full Support
  • Svelte
    • Svelte Stores: Full Support
  • Vue:
    • Vuex: Partial Support (Note: You can access a vuex store directly, but full vuex support requires the ability to set a custom vue.use(store) call to every component island. Planned.)

Are we missing your favorite state management library? Add it to the list above in a PR (or create an issue)!

💅 Styling

Styling in Astro is meant to be as flexible as youd like it to be! The following options are all supported:

Framework Global CSS Scoped CSS CSS Modules
Astro (.astro) N/A¹
React / Preact
Vue
Svelte

¹ .astro files have no runtime, therefore Scoped CSS takes the place of CSS Modules (styles are still scoped to components, but dont need dynamic values)

To learn more about writing styles in Astro, see our Styling Guide.

👉 Styling

🐶 Fetching Data

Fetching data is what Astro is all about! Whether your data lives remotely in an API or in your local project, Astro has got you covered.

For fetching from a remote API, use a native JavaScript fetch() (docs) as you are used to. For fetching local content, use Astro.fetchContent() (docs).

// src/components/MyComponent.Astro

---
// Example 1: fetch remote data from your own API
const remoteData = await fetch('https://api.mysite.com/v1/people').then((res) => res.json());

// Example 2: load local markdown files
const localData = Astro.fetchContent('../post/*.md');
---

🗺️ Sitemap

Astro will automatically create a /sitemap.xml for you for SEO! Be sure to set buildOptions.site in your Astro config so the URLs can be generated properly.

⚠️ Note that Astro wont inject this into your HTML for you! Youll have to add the tag yourself in your <head> on all pages that need it:

<link rel="sitemap" href="/sitemap.xml" />
Examples

🍱 Collections (beta)

Fetching data is easy in Astro. But what if you wanted to make a paginated blog? What if you wanted an easy way to sort data, or filter data based on part of the URL? Or generate an RSS 2.0 feed? When you need something a little more powerful than simple data fetching, Astros Collections API may be what you need.

👉 Collections API

⚙️ Config

👉 astro.config.mjs Reference

📚 API

👉 Full API Reference

👩🏽‍💻 CLI

👉 Command Line Docs

🏗 Development Server

👉 Dev Server Docs