Pre-release refactors (#289)

* refactor: expose `astro/components` as component entrypoint

* refactor: remove `extensions` from all configs

* test: fix snowpack tests

* docs: update config doc
This commit is contained in:
Nate Moore 2021-06-02 11:35:28 -05:00 committed by GitHub
parent 4dd18deab9
commit 94eac19888
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 55 additions and 247 deletions

View file

@ -4,34 +4,24 @@ To configure Astro, add an `astro.config.mjs` file in the root of your project.
```js ```js
export default { export default {
/** Where to resolve all URLs relative to. Useful if you have a monorepo project. */ projectRoot: '.', // Where to resolve all URLs relative to. Useful if you have a monorepo project.
projectRoot: '.', pages: './src/pages', // Path to Astro components, pages, and data
/** Path to your sites pages (routes) */ dist: './dist', // When running `astro build`, path to final static output
pages: './src/pages', public: './public', // A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that dont need processing.
/** When running `astro build`, path to final static output */
dist: './dist',
/** A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that dont need processing. */
public: './public',
/** Extension-specific handlings */
extensions: {
/** Set this to "preact" or "react" to determine what *.jsx files should load */
'.jsx': 'react',
},
/** Options specific to `astro build` */
buildOptions: { buildOptions: {
/** Your public domain, e.g.: https://my-site.dev/. Used to generate sitemaps and canonical URLs. */ // site: '', // Your public domain, e.g.: https://my-site.dev/. Used to generate sitemaps and canonical URLs.
site: '', sitemap: true, // Generate sitemap (set to "false" to disable)
/** Generate sitemap (set to "false" to disable) */
sitemap: true,
}, },
/** Options for the development server run with `astro dev`. */
devOptions: { devOptions: {
/** The port to run the dev server on. */ port: 3000, // The port to run the dev server on.
port: 3000, // tailwindConfig: '', // Path to tailwind.config.js if used, e.g. './tailwind.config.js'
/** Path to tailwind.config.js if used, e.g. './tailwind.config.js' */
tailwindConfig: undefined,
}, },
/** default array of rendering packages inserted into runtime */ // component renderers which are enabled by default
renderers: ['@astrojs/renderer-preact', '@astrojs/renderer-react', '@astrojs/renderer-svelte', '@astrojs/renderer-vue'], renderers: [
'@astrojs/renderer-svelte',
'@astrojs/renderer-vue',
'@astrojs/renderer-react',
'@astrojs/renderer-preact'
],
}; };
``` ```

View file

@ -58,7 +58,7 @@ Astro exposes a special `Markdown` component for `.astro` files which enables ma
--- ---
// For now, this import _must_ be named "Markdown" and _must not_ be wrapped with a custom component // For now, this import _must_ be named "Markdown" and _must not_ be wrapped with a custom component
// We're working on easing these restrictions! // We're working on easing these restrictions!
import Markdown from 'astro/components/Markdown.astro'; import { Markdown } from 'astro/components';
import Layout from '../layouts/main.astro'; import Layout from '../layouts/main.astro';
import MyFancyCodePreview from '../components/MyFancyCodePreview.tsx'; import MyFancyCodePreview from '../components/MyFancyCodePreview.tsx';
@ -101,7 +101,7 @@ If you have Markdown in a remote source, you may pass it directly to the Markdow
```jsx ```jsx
--- ---
import Markdown from 'astro/components/Markdown.astro'; import { Markdown } from 'astro/components';
const content = await fetch('https://raw.githubusercontent.com/snowpackjs/snowpack/main/README.md').then(res => res.text()); const content = await fetch('https://raw.githubusercontent.com/snowpackjs/snowpack/main/README.md').then(res => res.text());
--- ---
@ -115,7 +115,7 @@ Some times you might want to combine dynamic markdown with static markdown. You
```jsx ```jsx
--- ---
import Markdown from 'astro/components/Markdown.astro'; import { Markdown } from 'astro/components';
const content = await fetch('https://raw.githubusercontent.com/snowpackjs/snowpack/main/README.md').then(res => res.text()); const content = await fetch('https://raw.githubusercontent.com/snowpackjs/snowpack/main/README.md').then(res => res.text());
--- ---

View file

@ -1,7 +0,0 @@
export default {
extensions: {
'.jsx': 'react',
'.tsx': 'preact',
},
public: './public'
};

View file

@ -1,5 +1,5 @@
--- ---
import Markdown from 'astro/components/Markdown.astro'; import { Markdown } from 'astro/components';
import Layout from '../layouts/main.astro'; import Layout from '../layouts/main.astro';
import ReactCounter from '../components/ReactCounter.jsx'; import ReactCounter from '../components/ReactCounter.jsx';
import PreactCounter from '../components/PreactCounter.tsx'; import PreactCounter from '../components/PreactCounter.tsx';

View file

@ -1,5 +1,5 @@
export default { export default {
extensions: { renderers: [
'.tsx': 'preact' '@astrojs/renderer-preact'
} ]
}; };

View file

@ -1,5 +1,5 @@
--- ---
import Markdown from 'astro/components/Markdown.astro'; import { Markdown } from 'astro/components';
import Layout from '../layouts/Main.astro'; import Layout from '../layouts/Main.astro';
--- ---

View file

@ -1,5 +1,5 @@
export default { export default {
extensions: { renderers: [
'.jsx': 'preact', '@astrojs/renderer-preact'
}, ]
}; };

View file

@ -1,5 +0,0 @@
export default {
extensions: {
'.jsx': 'preact'
}
}

View file

@ -1,48 +0,0 @@
# Development Server
The development server comes as part of the Astro CLI. Start the server with:
```shell
astro dev
```
In your project root. You can specify an alternative
## Special routes
The dev server will serve the following special routes:
### /400
This is a custom **400** status code page. You can add this route by adding a page component to your `src/pages` folder:
```
├── src/
│ ├── components/
│ └── pages/
│ └── 400.astro
```
For any URL you visit that doesn't have a corresponding page, the `400.astro` file will be used.
### /500
This is a custom **500** status code page. You can add this route by adding a page component to your `src/pages` folder:
```astro
├── src/ │ ├── components/ │ └── pages/ │ └── 500.astro
```
This page is used any time an error occurs in the dev server.
The 500 page will receive an `error` query parameter which you can access with:
```
---
const error = Astro.request.url.searchParams.get('error');
---
<strong>{error}</strong>
```
A default error page is included with Astro so you will get pretty error messages even without adding a custom 500 page.

View file

@ -1,17 +0,0 @@
{
"name": "@example/remote-markdown",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "astro dev",
"build": "astro build",
"astro-dev": "nodemon --delay 0.5 -w ../../packages/astro/dist -x '../../packages/astro/astro.mjs dev'"
},
"devDependencies": {
"astro": "0.12.0-next.1",
"nodemon": "^2.0.7"
},
"snowpack": {
"workspaceRoot": "../.."
}
}

View file

@ -1,10 +0,0 @@
import { h, Fragment } from 'preact';
export default function Yell({ children }) {
return (
children
.filter((v) => typeof v === 'string')
.join('')
.toUpperCase() + '!'
);
}

View file

@ -1,14 +0,0 @@
---
export let content;
---
<html>
<head>
<title>{content.title}</title>
</head>
<body>
<slot />
<pre>{JSON.stringify(content)}</pre>
</body>
</html>

View file

@ -1,72 +0,0 @@
---
import Markdown from 'astro/components/Markdown.astro';
import Yell from '../components/Yell.jsx';
const title = 'INTERPOLATED';
const quietTest = 'interpolated';
const content = await fetch('https://raw.githubusercontent.com/snowpackjs/snowpack/main/README.md').then(res => res.text());
---
<!-- Basic -->
<Markdown>
# Hello world!
</Markdown>
<!-- Indented -->
<Markdown>
# Hello indent!
</Markdown>
<!-- Interpolation -->
<Markdown>
# Hello {title}!
</Markdown>
<!-- Can I break this? -->
<Markdown>
# I cannot!
<div>
# ahhhh
</div>
<Yell>{quietTest}</Yell>
<strong>Dope</strong>
`nice`
```
plain fence
```
```html
don't <div>me</div> bro
```
```js
Astro.fetchContent()
```
### cool stuff?
```astro
{'can\'t interpolate'}
{}
{title}
Do I break? <Markdown> </Markdown>
```
</Markdown>
<!-- external content -->
<Markdown>{content}</Markdown>
<!-- external with newlines -->
<Markdown>
{content}
</Markdown>
<!-- external with indentation -->
<Markdown>
{content}
</Markdown>

View file

@ -1,6 +0,0 @@
---
import Markdown from 'astro/components/Markdown.astro';
const content = await fetch('https://raw.githubusercontent.com/snowpackjs/snowpack/main/README.md').then(res => res.text());
---
<Markdown content={content} />

View file

@ -3,14 +3,9 @@ export default {
pages: './src/pages', pages: './src/pages',
dist: './dist', dist: './dist',
public: './public', public: './public',
extensions: { renderers: [
'.jsx': 'preact', '@astrojs/renderer-vue',
}, '@astrojs/renderer-svelte',
snowpack: { '@astrojs/renderer-preact'
optimize: { ]
bundle: false,
minify: true,
target: 'es2018',
},
},
}; };

View file

@ -0,0 +1,2 @@
export { default as Markdown } from './Markdown.astro';
export { default as Prism } from './Prism.astro';

View file

@ -9,6 +9,7 @@
".": "./astro.mjs", ".": "./astro.mjs",
"./package.json": "./package.json", "./package.json": "./package.json",
"./snowpack-plugin": "./snowpack-plugin.cjs", "./snowpack-plugin": "./snowpack-plugin.cjs",
"./components": "./components/index.js",
"./components/*": "./components/*", "./components/*": "./components/*",
"./runtime/svelte": "./dist/frontend/runtime/svelte.js", "./runtime/svelte": "./dist/frontend/runtime/svelte.js",
"./dist/frontend/markdown.js": "./dist/frontend/markdown.js" "./dist/frontend/markdown.js": "./dist/frontend/markdown.js"

View file

@ -1,5 +1,5 @@
--- ---
import Prism from 'astro/components/Prism.astro'; import { Prism } from 'astro/components';
let title = 'Uh oh...'; let title = 'Uh oh...';
const error = Astro.request.url.searchParams.get('error'); const error = Astro.request.url.searchParams.get('error');

View file

@ -1,6 +1,5 @@
export default { export default {
extensions: { renderers: [
'.jsx': 'preact' '@astrojs/renderer-preact'
} ]
} }

View file

@ -1,5 +1,5 @@
export default { export default {
extensions: { renderers: [
'.jsx': 'preact', '@astrojs/renderer-preact'
}, ]
}; }

View file

@ -1,5 +1,5 @@
--- ---
import Markdown from 'astro/components/Markdown.astro'; import { Markdown } from 'astro/components';
export const title = 'My Blog Post'; export const title = 'My Blog Post';
export const description = 'This is a post about some stuff.'; export const description = 'This is a post about some stuff.';
--- ---

View file

@ -1,5 +1,5 @@
--- ---
import Markdown from 'astro/components/Markdown.astro'; import { Markdown } from 'astro/components';
import Layout from '../layouts/content.astro'; import Layout from '../layouts/content.astro';
import Hello from '../components/Hello.jsx'; import Hello from '../components/Hello.jsx';
import Counter from '../components/Counter.jsx'; import Counter from '../components/Counter.jsx';

View file

@ -1,5 +1,5 @@
--- ---
import Markdown from 'astro/components/Markdown.astro'; import { Markdown } from 'astro/components';
import Hello from '../components/Hello.jsx'; import Hello from '../components/Hello.jsx';
const outer = `# Outer`; const outer = `# Outer`;

View file

@ -1,5 +1,5 @@
--- ---
import Markdown from 'astro/components/Markdown.astro'; import { Markdown } from 'astro/components';
import Layout from '../layouts/content.astro'; import Layout from '../layouts/content.astro';
import Example from '../components/Example.jsx'; import Example from '../components/Example.jsx';

View file

@ -1,5 +1,5 @@
export default { export default {
extensions: { renderers: [
'.jsx': 'preact', '@astrojs/renderer-preact'
}, ]
}; }

View file

@ -1,7 +1,7 @@
export default { export default {
extensions: { renderers: [
'.jsx': 'preact', '@astrojs/renderer-preact'
}, ],
buildOptions: { buildOptions: {
sitemap: false, sitemap: false,
}, },