Skip to content

Commit

Permalink
Merge branch 'main' into feat/hmr-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-lefebvre authored Apr 9, 2024
2 parents c8cb7d9 + b392eb9 commit 8123d2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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

0 comments on commit 8123d2a

Please sign in to comment.