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

Add CustomElements support #550

Closed
mikabytes opened this issue Feb 14, 2020 · 3 comments
Closed

Add CustomElements support #550

mikabytes opened this issue Feb 14, 2020 · 3 comments

Comments

@mikabytes
Copy link
Collaborator

Perhaps this idea is a bit esoteric, but consider this situation:

./file1.js

class MyCustomElement extends HTMLElement {
 ...
}

window.customElements.define("my-custom-element", MyCustomElement)

./file2.js

const mydom = html`<my-custom-element>Hello</my-custom-element`
document.body.append(mydom)

I'd like ImportJS to add import './file1.js' to file2.js

The html`` template literal syntax is widely adopted in JavaScript community. Used by LitHtml, with support by Prettier, syntax support is available for Vim, Visual Studio and probably many others. If we could teach ImportJS to understand them as well, it would be a great addition and a huge win for me :)

@trotzig
Copy link
Collaborator

trotzig commented Feb 14, 2020

I think this makes sense. I personally don't have a need for this but I'd be happy to help reviewing a PR! There are two parts to this. First, we need to make sure the "export" syntax in ./file1.js is recognized and indexed by import-js (here I think). Then we need to find custom elements like the ones in ./file2.js, likely here: https://github.com/Galooshi/import-js/blob/master/lib/findUsedIdentifiers.js

@mikabytes
Copy link
Collaborator Author

Thanks for the pointers! I might start work on this already tomorrow if nothing else comes up.

I think we also need a configuration option to enable/disable this feature. Some people like to import their custom elements in a separate file (custom elements is a global registry)

@mikabytes
Copy link
Collaborator Author

It's been 2 years.

While I did implement a solution that worked for my use case, it was evident in my company that it was too opinionated to be made into a general solution. People name their custom elements based on their convention.

In the end, I had an idea for a more general plugin-style extension for ImportJS but never got around to writing it.

Closing this due to it being stale. Might reopen in the future.

This was referenced Feb 4, 2024
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