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: enable custom collections #12

Open
JessicaSachs opened this issue Nov 29, 2021 · 6 comments
Open

feat: enable custom collections #12

JessicaSachs opened this issue Nov 29, 2021 · 6 comments

Comments

@JessicaSachs
Copy link

👋🏻 Hello! I (and Cypress) use your custom icons plugin via the Unplugin ecosystem. Thanks for all the great work! I'm interested in adding support for custom collections.

I'd be willing to implement it if you pointed me in the right direction.

@antfu
Copy link
Owner

antfu commented Nov 30, 2021

I guess at this point, we might need to unify the behaviour and configurations in unplugin-icons, this extension, @unocss/preset-icons to have the same interface and ability to add custom icons. It could be a bit tricky since VS Code are using a different process as your local Node process (Vite). Meaning we need to find a way to share the config for Vite and the VS Code extension.

Here are two solutions that come to my mind,

  1. Introduce a new config file like icons.config.ts for plugins to load from, just like we have windi.config.ts or postcss.config.js etc.
  2. Make a general tool to load configs from various configure files, like we could load from standalone file, or even extract the plugin config from vite.config.ts or webpack.config.js.

The downside of solution one is that we probably end up with too many config files and for ppl who don't outsource their config, they can't benefit from the extension or other integrations. I am leaner to solution two, which I believe provides better DX and could also be useful if we are end with building a VS Code extension for UnoCSS and maybe for the future of Windi and others. The only thing is that we need to do a PoC of solution two to see if it's really feasible tho.

@antfu
Copy link
Owner

antfu commented Nov 30, 2021

Ok I made it https://github.com/antfu/unconfig, and it's working. You can see an example usage here https://github.com/antfu/unplugin-icons/blob/main/examples/vite-vue3/getConfig.ts

It's currently using https://github.com/egoist/bundle-require which is based on esbuild, which I guess it's not compatible with VS Code extension env. We might need to switch to some pure JS solution like https://github.com/alangpierce/sucrase later.

@JessicaSachs
Copy link
Author

OK I understand the two approaches and the problem you're trying to solve by unifying the icon library configurations across the three tools we have. I'm trying to understand the last comment. I'll pull down and test out your example repo. I mostly don't understand if you expect the VSCode plugin to work (given your comment about esbuild/VSCode compat).

The other thing I don't understand is how getConfig is consumed and by whom. If you had instructions for how to test, that would be super helpful 💯. My main concern from reading your comment is that getConfig is almost like a resolved build config -- like node_modules/@vue/cli-service/webpack.config.js is. I doubt that's what's happening, but that's what the code in getConfig looks like it's doing.

@antfu
Copy link
Owner

antfu commented Dec 1, 2021

In this extension, we could call

import { loadConfig } from 'unconfig'

const { config } = await loadConfig({ sources: [...] })

for (const c of config.customCollections) {
  // ...
}

I just made the UnoCSS extension using unconfig (it's now working on non-Node env)

@itpropro
Copy link

itpropro commented Aug 17, 2022

I am using some custom imported JSON icon sets to integrate font awesome pro with unocss/presetIcons like this:

    presetIcons({
      scale: 1.2,
      warn: true,
      collections: {
        'fa-solid': async () => JSON.parse(await fs.readFile('./icons/fa-solid.json', 'utf8')),
      }
    }),

It would be great, if the extension would also show these as actual icons instead of just the svg content on hover (which comes from unocss intellisense). Here is an example with a free icon from that set:
image

If it helps for testing, I can create a minimal reproduction repo with just a few icons in the JSON file @antfu.
If you already started implementing something similar @JessicaSachs, I would like to support :)

@s3xysteak
Copy link
Contributor

Hope unplugin-iconify-generator could help you!

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

4 participants