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(astro): incorrect path and build failure #2648

Merged
merged 2 commits into from May 22, 2023
Merged
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
20 changes: 15 additions & 5 deletions packages/astro/src/index.ts
Expand Up @@ -4,7 +4,7 @@ import type { AstroIntegration } from 'astro'
import type { VitePluginConfig } from '@unocss/vite'
import VitePlugin from '@unocss/vite'
import type { UserConfigDefaults } from '@unocss/core'
import type { Plugin } from 'vite'
import type { Plugin, ResolvedConfig } from 'vite'

const UNO_INJECT_ID = 'uno-astro'
const UNO_QUERY_KEY = 'uno-with-astro-key'
Expand All @@ -15,15 +15,25 @@ interface AstroVitePluginOptions {

function AstroVitePlugin(options: AstroVitePluginOptions): Plugin {
const { injects } = options

let config: ResolvedConfig

return {
name: 'unocss:astro',
apply: 'serve',
enforce: 'pre',
resolveId(id, importer) {
configResolved(_config) {
config = _config
},
async resolveId(id, importer) {
if (id === UNO_INJECT_ID)
return id
if (importer?.endsWith(UNO_INJECT_ID))
return `${id}${id.includes('?') ? '&' : '?'}${UNO_QUERY_KEY}`
if (importer?.endsWith(UNO_INJECT_ID) && config && config.command === 'serve') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need remove && config here @antfu Can you help me?

const resolved = await this.resolve(id, importer, { skipSelf: true })
if (resolved) {
const fsPath = resolved.id
return `${fsPath}${fsPath.includes('?') ? '&' : '?'}${UNO_QUERY_KEY}`
}
}
},
load(id, options) {
if (id.endsWith(UNO_INJECT_ID))
Expand Down