Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docs): add missing name #97

Merged
merged 1 commit into from
Apr 9, 2024
Merged
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
10 changes: 8 additions & 2 deletions docs/src/content/docs/utilities/add-virtual-imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ description: Allows adding Vite virtual modules easily to access data across you

`addVirtualImports` allows you to create virtual modules and share data from your integration. For example:

```ts title="my-integration/index.ts" {3,11-15,17-30}
```ts title="my-integration/index.ts" {3,11-16,18-32} "name"
import {
defineIntegration,
addVirtualImports
} from "astro-integration-kit";

export default defineIntegration({
// ...
setup() {
setup({ name }) {
return {
"astro:config:setup": (params) => {
addVirtualImports(params, {
name,
imports: {
'virtual:my-integration/config': `export default ${JSON.stringify({ foo: "bar" })}`,
}
})

addVirtualImports(params, {
name,
imports: [
{
id: "virtual:my-integration/advanced",
Expand All @@ -49,6 +51,10 @@ While you can choose any name for your virtual module, it's a good idea to stick
- If you want your module to be used by your end user, in other words someone who will install your integration, follow this pattern: `${integrationName}/${moduleName}`
:::

:::note
You should pass the integration name as the `name` option. You can obtain it from the `setup` arguments.
:::

You can now access the config somewhere else, for example inside a page injected by your integration:

```ts title="my-integration/src/pages/index.astro"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "root",
"private": true,
"packageManager": "[email protected].2",
"packageManager": "[email protected].6",
"engines": {
"node": ">=18.19.0"
},
Expand Down
Loading