https://github.com/brycerussell/astro-public
Add custom "public" directories for static assets in Astro
https://github.com/brycerussell/astro-public
Last synced: about 1 year ago
JSON representation
Add custom "public" directories for static assets in Astro
- Host: GitHub
- URL: https://github.com/brycerussell/astro-public
- Owner: BryceRussell
- Created: 2024-02-23T05:37:42.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-10T00:41:46.000Z (over 1 year ago)
- Last Synced: 2025-03-12T10:02:44.801Z (over 1 year ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/astro-public
- Size: 1.53 MB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `astro-public`
[](https://www.npmjs.com/package/astro-public)
[](https://github.com/BryceRussell/astro-public/tree/main/package)
Add custom "public" directories for static assets in Astro
### Why?
1. Serve static assets from anywhere, including packages
2. Have multiple static asset directories instead of only the default public directory
3. Provide placeholder assets that can be overwritten by assets in Astro's public directory
### [Documentation](https://github.com/BryceRussell/astro-public/tree/main/package)
### Example
#### Use as an Integration
```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import publicDir from 'astro-public';
export default defineConfig({
// Creates a 'public' directory at '/static'
integrations: [publicDir('static')],
});
```
#### Use Inside an Integration
```ts
// package/index.ts
import type { AstroIntegration } from "astro";
import { addIntegration } from "astro-integration-kit";
import publicDir from "astro-public";
export default function myIntegration(): AstroIntegration {
return {
name: "my-integration",
hooks: {
"astro:config:setup": ({
updateConfig,
config,
logger,
}) => {
// Creates a 'public' directory at '/package/static'
addIntegration({
integration: publicDir({
dir: "static",
cwd: import.meta.url
}),
updateConfig,
config,
logger,
})
}
}
}
}
```