-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent CSS from being added to pages not using it (#2918)
* Prevent CSS from being added to pages not using it * Adds a changeset * Add clarification when the CSS is appended to the pageData * Move addStyles up a level
- Loading branch information
Showing
12 changed files
with
153 additions
and
7 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 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Prevent CSS from being added to the wrong pages |
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
13 changes: 13 additions & 0 deletions
13
packages/astro/test/fixtures/page-level-styles/src/layouts/Base.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,13 @@ | ||
--- | ||
--- | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<title>Astro</title> | ||
</head> | ||
<body> | ||
<slot /> | ||
</body> | ||
</html> |
13 changes: 13 additions & 0 deletions
13
packages/astro/test/fixtures/page-level-styles/src/layouts/Styled.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,13 @@ | ||
--- | ||
import "../styles/main.css"; | ||
--- | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<title>Astro</title> | ||
</head> | ||
<body> | ||
<slot /> | ||
</body> | ||
</html> |
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/page-level-styles/src/pages/blog.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,9 @@ | ||
--- | ||
import Layout from '../layouts/Styled.astro' | ||
--- | ||
|
||
<Layout> | ||
<h1>Astro (with main.css)</h1> | ||
<p>This should have custom styles (white text on black background)</p> | ||
<a href="/">Home (without main.css)</a> | ||
</Layout> |
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/page-level-styles/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,9 @@ | ||
--- | ||
import Layout from '../layouts/Base.astro' | ||
--- | ||
|
||
<Layout> | ||
<h1>Astro (without main.css)</h1> | ||
<p>This should have default styles (white text on black background)</p> | ||
<a href="/blog">Blog (with main.css)</a> | ||
</Layout> |
4 changes: 4 additions & 0 deletions
4
packages/astro/test/fixtures/page-level-styles/src/styles/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,4 @@ | ||
body { | ||
background-color: black; | ||
color: white; | ||
} |
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,27 @@ | ||
import { expect } from 'chai'; | ||
import { load as cheerioLoad } from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
// Asset bundling | ||
describe('Page-level styles', () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
projectRoot: './fixtures/page-level-styles/', | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('Doesn\'t add page styles for a page without style imports', async () => { | ||
let html = await fixture.readFile('/index.html'); | ||
let $ = await cheerioLoad(html); | ||
expect($('link').length).to.equal(0); | ||
}); | ||
|
||
it('Does add page styles for pages with style imports (or deps)', async () => { | ||
let html = await fixture.readFile('/blog/index.html'); | ||
let $ = await cheerioLoad(html); | ||
expect($('link').length).to.equal(1); | ||
}); | ||
}); |