-
-
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.
Add
vite.build.cssTarget
support for CSS build (#4155)
* Add `vite.build.cssTarget` support for CSS build * chore: update lockfile Co-authored-by: Nate Moore <nate@astro.build>
- Loading branch information
1 parent
3362ec2
commit 81c9ad9
Showing
8 changed files
with
91 additions
and
0 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': minor | ||
--- | ||
|
||
Add `vite.build.cssTaregt` support for CSS 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
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,39 @@ | ||
/** | ||
* css-target | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
let fixture; | ||
|
||
describe('CSS', function () { | ||
before(async () => { | ||
fixture = await loadFixture({ root: './fixtures/config-vite-css-target/' }); | ||
}); | ||
|
||
describe('build', () => { | ||
let $; | ||
let html; | ||
let bundledCSS; | ||
|
||
before(async () => { | ||
await fixture.build(); | ||
|
||
// get bundled CSS (will be hashed, hence DOM query) | ||
html = await fixture.readFile('/index.html'); | ||
$ = cheerio.load(html); | ||
const bundledCSSHREF = $('link[rel=stylesheet][href^=/assets/]').attr('href'); | ||
bundledCSS = (await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/'))) | ||
.replace(/\s/g, '') | ||
.replace('/n', ''); | ||
}); | ||
|
||
it('vite.build.cssTarget is respected', async () => { | ||
expect(bundledCSS).to.match( | ||
new RegExp('.class\\:where\\(.astro-[^{]*{top:0;right:0;bottom:0;left:0}') | ||
); | ||
}); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/config-vite-css-target/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,9 @@ | ||
import { defineConfig } from 'astro/config'; | ||
|
||
export default defineConfig({ | ||
vite: { | ||
build: { | ||
cssTarget: "safari14", | ||
} | ||
} | ||
}) |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/config-vite-css-target/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,8 @@ | ||
{ | ||
"name": "@test/config-vite-css-target", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/astro/test/fixtures/config-vite-css-target/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,18 @@ | ||
<html> | ||
<head> | ||
<title>css-target</title> | ||
</head> | ||
<body> | ||
<h1>css-target</h1> | ||
<div class="class"></div> | ||
</body> | ||
</html> | ||
|
||
<style> | ||
.class { | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
} | ||
</style> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.