Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ coverage/
.next
docs/

# prevent declaration files in src directories
# prevent build artifacts in src directories
packages/*/src/**/*.js
packages/*/src/**/*.js.map
packages/*/src/**/*.d.ts
packages/*/src/**/*.d.ts.map

# cache
.turbo
Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"coverage",
"*.min.js",
".husky",
"*.tsbuildinfo"
"*.tsbuildinfo",
"**/*.astro"
]
}
}
13 changes: 0 additions & 13 deletions examples/blog/index.html

This file was deleted.

4 changes: 4 additions & 0 deletions examples/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@minimal-astro/compiler": "workspace:*"
},
"devDependencies": {
"@minimal-astro/vite-plugin": "workspace:*",
"vite": "^5.4.11"
}
}
1 change: 0 additions & 1 deletion examples/blog/public/vite.svg

This file was deleted.

43 changes: 43 additions & 0 deletions examples/blog/src/about.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
const title = 'About minimal-astro'
const author = {
name: 'Kenji',
role: 'Developer',
description: 'Building a minimal implementation of Astro to understand its internals.',
}
const createdAt = new Date().toLocaleDateString('ja-JP')
---

<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{title}</title>
</head>
<body>
<h1>{title}</h1>

<section>
<h2>About this project</h2>
<p>minimal-astro is an educational project that reimplements core features of Astro from scratch.</p>

<h3>Author</h3>
<dl>
<dt>Name</dt>
<dd>{author.name}</dd>

<dt>Role</dt>
<dd>{author.role}</dd>

<dt>Description</dt>
<dd>{author.description}</dd>
</dl>

<p>Created on: {createdAt}</p>
</section>

<nav>
<a href="/">Back to Home</a>
</nav>
</body>
</html>
9 changes: 0 additions & 9 deletions examples/blog/src/counter.js

This file was deleted.

26 changes: 26 additions & 0 deletions examples/blog/src/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
const title = 'Hello minimal-astro'
const message = 'Welcome to minimal-astro!'
const items = ['Fast by default', 'Island Architecture', 'Multi-framework support']
---

<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{title}</title>
</head>
<body>
<h1>{message}</h1>
<p>This is a minimal implementation of Astro, built from scratch.</p>

<h2>Features</h2>
<ul>
{items.map(item => <li>{item}</li>)}
</ul>

<nav>
<a href="/about">About</a>
</nav>
</body>
</html>
1 change: 0 additions & 1 deletion examples/blog/src/javascript.svg

This file was deleted.

24 changes: 0 additions & 24 deletions examples/blog/src/main.js

This file was deleted.

96 changes: 0 additions & 96 deletions examples/blog/src/style.css

This file was deleted.

11 changes: 11 additions & 0 deletions examples/blog/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { vitePluginAstro } from '@minimal-astro/vite-plugin'
import { defineConfig } from 'vite'

export default defineConfig({
plugins: [vitePluginAstro()],
build: {
rollupOptions: {
input: './src/index.astro',
},
},
})
32 changes: 10 additions & 22 deletions packages/compiler/src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,28 +153,16 @@ function parseElement(state: ParserState): { node: ElementNode; state: ParserSta

let attrValue: string | ExpressionNode = ''

// Skip whitespace and equals
while (peek(currentState).type === 'TEXT' && peek(currentState).value.trim() === '') {
currentState = advance(currentState).state
}

if (peek(currentState).value === '=') {
currentState = advance(currentState).state // Skip =

// Skip whitespace
while (peek(currentState).type === 'TEXT' && peek(currentState).value.trim() === '') {
currentState = advance(currentState).state
}

if (peek(currentState).type === 'HTML_ATTRIBUTE_VALUE') {
const valueResult = advance(currentState)
attrValue = valueResult.token.value
currentState = valueResult.state
} else if (peek(currentState).type === 'EXPRESSION_START') {
const exprResult = parseExpression(currentState)
attrValue = exprResult.node as ExpressionNode
currentState = exprResult.state
}
// Check if next token is the attribute value
if (peek(currentState).type === 'HTML_ATTRIBUTE_VALUE') {
const valueResult = advance(currentState)
attrValue = valueResult.token.value
currentState = valueResult.state
} else if (peek(currentState).type === 'EXPRESSION_START') {
// Handle dynamic attribute values like class={className}
const exprResult = parseExpression(currentState)
attrValue = exprResult.node as ExpressionNode
currentState = exprResult.state
}

attributes.push({ name: attrName, value: attrValue })
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"noEmit": false,
"tsBuildInfoFile": "./dist/.tsbuildinfo"
},
"include": ["src/**/*"],
Expand Down
52 changes: 52 additions & 0 deletions packages/vite-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# @minimal-astro/vite-plugin

Vite plugin for transforming `.astro` files in the minimal-astro project.

## Current Status

This is a **stub implementation** that provides basic transformation of `.astro` files to JavaScript modules. The current implementation:

- ✅ Parses `.astro` files using `@minimal-astro/compiler`
- ✅ Builds HTML from the AST
- ✅ Exports the HTML as a default export
- ⚠️ Does not handle component imports/exports
- ⚠️ Does not support client-side hydration
- ⚠️ Does not extract CSS
- ⚠️ Does not provide proper HMR support (uses full reload)

## Usage

```typescript
// vite.config.ts
import { defineConfig } from 'vite'
import { vitePluginAstro } from '@minimal-astro/vite-plugin'

export default defineConfig({
plugins: [vitePluginAstro()]
})
```

## Development

```bash
# Install dependencies
pnpm install

# Build the plugin
pnpm build

# Run tests
pnpm test

# Watch mode
pnpm dev
```

## Future Enhancements

1. **Component Support**: Handle imports and exports in frontmatter
2. **Hydration**: Implement client-side hydration strategies
3. **CSS Extraction**: Extract and process styles from components
4. **HMR**: Implement proper Hot Module Replacement
5. **Source Maps**: Generate source maps for debugging
6. **Error Handling**: Better error messages and recovery
Loading
Loading