Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core)!: default preflights to preflights layer #1190

Merged
merged 2 commits into from Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions packages/core/src/generator/index.ts
Expand Up @@ -175,20 +175,18 @@ export class UnoGenerator {
theme: this.config.theme,
}

const preflightLayerSet = new Set<string>(['default'])
this.config.preflights.forEach(({ layer }) => {
if (layer) {
layerSet.add(layer)
preflightLayerSet.add(layer)
}
const preflightLayerSet = new Set<string>([])
this.config.preflights.forEach(({ layer = 'preflights' }) => {
layerSet.add(layer)
preflightLayerSet.add(layer)
})

preflightsMap = Object.fromEntries(
await Promise.all(Array.from(preflightLayerSet).map(
async (layer) => {
const preflights = await Promise.all(
this.config.preflights
.filter(i => (i.layer || 'default') === layer)
.filter(i => (i.layer || 'preflights') === layer)
.map(async i => await i.getCSS(preflightContext)),
)
const css = preflights
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/preflights.test.ts.snap
@@ -1,8 +1,8 @@
// Vitest Snapshot v1

exports[`preflights > basic 1`] = `
"/* layer: default */
"/* layer: preflights */
.default-preflight {}
/* layer: preflight */
/* layer: custom */
.hello { text: red }"
`;
2 changes: 1 addition & 1 deletion test/preflights.test.ts
Expand Up @@ -9,7 +9,7 @@ describe('preflights', () => {
getCSS() {
return '.hello { text: red }'
},
layer: 'preflight',
layer: 'custom',
},
{
getCSS() { return undefined },
Expand Down