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

fix(vite): move @import before other rules #3743

Merged
merged 1 commit into from May 8, 2024
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
6 changes: 4 additions & 2 deletions packages/vite/src/modes/global/build.ts
Expand Up @@ -17,6 +17,7 @@ import {
} from '../../integration'
import type { VitePluginConfig } from '../../types'
import { setupContentExtractor } from '../../../../shared-integration/src/content'
import { LAYER_IMPORTS } from '../../../../core/src/constants'

// https://github.com/vitejs/vite/blob/main/packages/plugin-legacy/src/index.ts#L742-L744
function isLegacyChunk(chunk: RenderedChunk, options: NormalizedOutputOptions) {
Expand Down Expand Up @@ -218,9 +219,10 @@ export function GlobalModeBuildPlugin(ctx: UnocssPluginContext<VitePluginConfig>
}
const result = await generateAll()
const mappedVfsLayer = Array.from(vfsLayers).map(layer => layer === LAYER_MARK_ALL ? layer : layer.replace(/^_/, ''))
const cssWithLayers = Array.from(vfsLayers).map(layer => `#--unocss-layer-start--${layer}--{start:${layer}} ${
const importStatements = result.getLayer(LAYER_IMPORTS)
const cssWithLayers = Array.from(vfsLayers).map(layer => `${importStatements ?? ''}#--unocss-layer-start--${layer}--{start:${layer}} ${
layer === LAYER_MARK_ALL
? result.getLayers(undefined, mappedVfsLayer)
? result.getLayers(undefined, [...mappedVfsLayer, LAYER_IMPORTS])
: (result.getLayer(layer.replace(/^_/, '')) || '')
} #--unocss-layer-end--${layer}--{end:${layer}}`).join('')

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/modes/global/dev.ts
Expand Up @@ -161,7 +161,7 @@ export function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedMo
const { hash, css } = await generateCSS(layer)
return {
// add hash to the chunk of CSS that it will send back to client to check if there is new CSS generated
code: `__uno_hash_${hash}{--:'';}${css}`,
code: `${css}__uno_hash_${hash}{--:'';}`,
map: { mappings: '' },
}
},
Expand Down