-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Vue] add support for
appEntrypoint
(#5075)
* feat(vue): add support for appEntrypoint * chore: add changeset * test(vue): add tests for app entrypoint * docs(vue): update README to include app entrypoint * fix(vue): prefer resolvedVirtualModuleId Co-authored-by: Nate Moore <[email protected]>
- Loading branch information
1 parent
6f9a88b
commit d25f54c
Showing
15 changed files
with
205 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
'@astrojs/vue': minor | ||
--- | ||
|
||
Add support for the `appEntrypoint` option, which accepts a root-relative path to an app entrypoint. The default export of this file should be a function that accepts a Vue `App` instance prior to rendering. This opens up the ability to extend the `App` instance with [custom Vue plugins](https://vuejs.org/guide/reusability/plugins.html). | ||
|
||
```js | ||
// astro.config.mjs | ||
import { defineConfig } from 'astro/config'; | ||
import vue from '@astrojs/vue'; | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
vue({ | ||
appEntrypoint: '/src/pages/_app' | ||
}) | ||
] | ||
}) | ||
``` | ||
|
||
```js | ||
// src/pages/_app.ts | ||
import type { App } from 'vue'; | ||
import i18nPlugin from '../plugins/i18n' | ||
|
||
export default function setup(app: App) { | ||
app.use(i18nPlugin, { /* options */ }) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { loadFixture } from './test-utils.js'; | ||
import { expect } from 'chai'; | ||
import { parseHTML } from 'linkedom'; | ||
|
||
describe('App Entrypoint', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/app-entrypoint/' | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('loads during SSR', async () => { | ||
const data = await fixture.readFile('/index.html') | ||
const { document } = parseHTML(data); | ||
const bar = document.querySelector('#foo > #bar'); | ||
expect(bar).not.to.be.undefined; | ||
expect(bar.textContent).to.eq('works'); | ||
}); | ||
|
||
it('setup included in renderer bundle', async () => { | ||
const data = await fixture.readFile('/index.html') | ||
const { document } = parseHTML(data); | ||
const island = document.querySelector('astro-island'); | ||
const client = island.getAttribute('renderer-url'); | ||
expect(client).not.to.be.undefined; | ||
|
||
const js = await fixture.readFile(client); | ||
expect(js).to.match(/\w+\.component\(\"Bar\"/gm) | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/integrations/vue/test/fixtures/app-entrypoint/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import vue from '@astrojs/vue'; | ||
|
||
export default defineConfig({ | ||
integrations: [vue({ | ||
appEntrypoint: '/src/pages/_app' | ||
})] | ||
}) |
9 changes: 9 additions & 0 deletions
9
packages/integrations/vue/test/fixtures/app-entrypoint/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@test/vue-app-entrypoint", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/vue": "workspace:*" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/integrations/vue/test/fixtures/app-entrypoint/src/components/Bar.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<div id="bar">works</div> | ||
</template> |
5 changes: 5 additions & 0 deletions
5
packages/integrations/vue/test/fixtures/app-entrypoint/src/components/Foo.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div id="foo"> | ||
<Bar /> | ||
</div> | ||
</template> |
6 changes: 6 additions & 0 deletions
6
packages/integrations/vue/test/fixtures/app-entrypoint/src/pages/_app.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { App } from 'vue' | ||
import Bar from '../components/Bar.vue' | ||
|
||
export default function setup(app: App) { | ||
app.component('Bar', Bar); | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/integrations/vue/test/fixtures/app-entrypoint/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
import Foo from '../components/Foo.vue'; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<title>Vue App Entrypoint</title> | ||
</head> | ||
<body> | ||
<Foo client:load /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js'; | ||
|
||
/** | ||
* @typedef {import('../../../astro/test/test-utils').Fixture} Fixture | ||
*/ | ||
|
||
export function loadFixture(inlineConfig) { | ||
if (!inlineConfig || !inlineConfig.root) | ||
throw new Error("Must provide { root: './fixtures/...' }"); | ||
|
||
// resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath | ||
// without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` | ||
return baseLoadFixture({ | ||
...inlineConfig, | ||
root: new URL(inlineConfig.root, import.meta.url).toString(), | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.