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: support obtaining unocss context externally #2738

Closed
4 tasks done
hairyf opened this issue Jun 7, 2023 · 1 comment
Closed
4 tasks done

feat: support obtaining unocss context externally #2738

hairyf opened this issue Jun 7, 2023 · 1 comment

Comments

@hairyf
Copy link

hairyf commented Jun 7, 2023

Clear and concise description of the problem

Hi, I would like to develop a plugin based on unocss externally (using unocss ctx).

https://github.com/unocss/unocss/blob/main/packages/vite/src/index.ts#L29

However, currently there is no way to access unocss ctx from outside the plugin. Is there any support for accessing it?

Suggested solution

I'm not sure about this, but perhaps you can add a new hook in the plugin? For example:

// use promise or hooks
const deferred = createDeferred<UnocssCtx>()

const plugins = [
  unocss({
    // resolve unocss config and ctgx
    configResolved: deferred.resolve
  }),
  myPlugin(deferred)
]

or use context callback

import { createContextLoader } from '@unocss/core'

function myPlugin() {
  let context
  const loader = createContextLoader()
  loader.load().then(v => context = v)
  return { /* ... */}
}

const plugins = [
   {
      myPlugin()
   }
]

Alternative

No response

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Read the README.md of using the package.
  • Already used the Interactive Docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@stale
Copy link

stale bot commented Aug 8, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants