-
-
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.
Ensure
appEntrypoint
is referenced in Vue components (#9490)
* fix(#6827): ensure `appEntrypoint` is referenced in Vue components * chore: add test * chore: add changeset * fix: windows handling * Update packages/integrations/vue/src/index.ts Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> * chore: address review feedback * chore: update lockfile --------- Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
- Loading branch information
1 parent
bd3f36e
commit a1c3166
Showing
12 changed files
with
160 additions
and
5 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,5 @@ | ||
--- | ||
'@astrojs/vue': patch | ||
--- | ||
|
||
Fixes a bug that caused styles referenced by `appEntrypoint` to be excluded from the build |
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,67 @@ | ||
import { loadFixture } from './test-utils.js'; | ||
import { expect } from 'chai'; | ||
import { load as cheerioLoad } from 'cheerio'; | ||
|
||
describe('App Entrypoint CSS', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/app-entrypoint-css/', | ||
}); | ||
}) | ||
|
||
describe('build', () => { | ||
before(async () => { | ||
await fixture.build(); | ||
}) | ||
|
||
it('injects styles referenced in appEntrypoint', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerioLoad(html); | ||
|
||
// test 1: basic component renders | ||
expect($('#foo > #bar').text()).to.eq('works'); | ||
|
||
// test 2: injects the global style on the page | ||
expect($('style').first().text().trim()).to.eq(':root{background-color:red}'); | ||
}); | ||
|
||
it('does not inject styles to pages without a Vue component', async () => { | ||
const html = await fixture.readFile('/unrelated/index.html'); | ||
const $ = cheerioLoad(html); | ||
|
||
expect($('style').length).to.eq(0); | ||
expect($('link[rel="stylesheet"]').length).to.eq(0); | ||
}); | ||
}) | ||
|
||
describe('dev', () => { | ||
let devServer; | ||
before(async () => { | ||
devServer = await fixture.startDevServer(); | ||
}) | ||
after(async () => { | ||
await devServer.stop(); | ||
}) | ||
|
||
it('loads during SSR', async () => { | ||
const html = await fixture.fetch('/').then((res) => res.text()); | ||
const $ = cheerioLoad(html); | ||
|
||
// test 1: basic component renders | ||
expect($('#foo > #bar').text()).to.eq('works'); | ||
// test 2: injects the global style on the page | ||
expect($('style').first().text().replace(/\s+/g, '')).to.eq(':root{background-color:red;}'); | ||
}); | ||
|
||
it('does not inject styles to pages without a Vue component', async () => { | ||
const html = await fixture.fetch('/unrelated').then((res) => res.text()); | ||
const $ = cheerioLoad(html); | ||
|
||
expect($('style').length).to.eq(0); | ||
expect($('link[rel="stylesheet"]').length).to.eq(0); | ||
}); | ||
}) | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/integrations/vue/test/fixtures/app-entrypoint-css/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/app.ts' }) | ||
], | ||
}) |
9 changes: 9 additions & 0 deletions
9
packages/integrations/vue/test/fixtures/app-entrypoint-css/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-css", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@astrojs/vue": "workspace:*", | ||
"astro": "workspace:*" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/integrations/vue/test/fixtures/app-entrypoint-css/src/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,9 @@ | ||
import type { App } from 'vue' | ||
import Bar from './components/Bar.vue' | ||
// Important! Test that styles here are injected to the page | ||
import '/src/main.css' | ||
|
||
|
||
export default function setup(app: App) { | ||
app.component('Bar', Bar); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/integrations/vue/test/fixtures/app-entrypoint-css/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-css/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> |
3 changes: 3 additions & 0 deletions
3
packages/integrations/vue/test/fixtures/app-entrypoint-css/src/main.css
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 @@ | ||
:root { | ||
background-color: red; | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/integrations/vue/test/fixtures/app-entrypoint-css/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> |
8 changes: 8 additions & 0 deletions
8
packages/integrations/vue/test/fixtures/app-entrypoint-css/src/pages/unrelated.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,8 @@ | ||
<html> | ||
<head> | ||
<title>Unrelated page</title> | ||
</head> | ||
<body> | ||
<h1>I shouldn't have styles</h1> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.