Repository navigation
Standalone .astro file usage
#1378
Replies: 3 comments 12 replies
|
The biggest hurdle here is that I'm sure it's possible to untangle all of these things into an API that makes sense and is nice, but it's a lot of work. Looking at the prototype, what's missing are tests / examples that show using this outside of Astro. I'd be curious to see what that looks like. Figuring that part out would also unearth all of the parts that need to be pulled into the plugin (which is likely quite a bit, including a lot of the build, but that's ok of course). |
Astro as composable Vite pluginsSummarySplit Background & MotivationAstro has become a collection of strong primitives — the However currently using this is an all-or-nothing proposition. If you want to use something else for a particular task you can, but you will incur the cost in package size nonetheless, which often pushes you towards using the built-in primitives. For Astro this presents a risk, if the perception of any of the parts is negative it can lead to negative feelings about the framework as a whole. Additionally, many projects do not start out using Astro, but they do start out using Vite. Making Astro available as a plugin lets those people upgrade to use Astro without rewriting their entire application. Goals
Non-goals
ExampleJust the language — Astro components rendered by Hono routes, with a React island: // vite.config.js
import astro from '@astrojs/vite-plugin-astro';
import react from '@astrojs/react/renderer';
export default { plugins: [astro({
renderers: [react()]
})] };// src/app.ts
import { renderToResponse } from '@astrojs/runtime';
import Page from './components/Page.astro';
const app = new Hono();
app.get('/hello/:name', (c) => renderToResponse(Page, { props: { name: c.req.param('name') } }));Pages — a site with file routing and nothing else: import astro from '@astrojs/vite-plugin-astro';
import pages from '@astrojs/vite-plugin-pages';
export default { plugins: [astro(), pages()] }; // vite dev / vite buildPick your features: export default {
plugins: [
astro({ site: 'https://example.com' }),
pages({ output: 'server' }),
content(),
markdown(),
assets(),
i18n({ defaultLocale: 'en', locales: ['en', 'es'] }),
// no actions, no sessions, no toolbar
],
}; |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Body
Summary
Be able to easily use
.astrofiles in non Astro projects.Background & Motivation
A huge part of Astro's success can be attributed, I think, to the
.astrofile format (Recently a proper spec was made: withastro/compiler#1138). It's super easy to reason about and it's powerful.However
.astrofiles are currently only usable in Astro projects. But I think some projects would be happy to adopt purely as a file format, without bringing all of Astro alongside. For example, usage in pure Vite projects for more custom setups.I'm also wondering if that could help with / replace the Container API.
Goals
.astrofiles in Vite.astrofilesExample
We already have the compiler which is great! I'm suggesting we have a new
vite-plugin-astropackage (already experimented with it in withastro/astro#17094) as well as a package purely usable for rendering (including jsx rendering, this way it also covers types).Most of the work is extracting stuff from core into public packages, then use these packages back in core.
All reactions