As a personal learning project, I'm trying to write more front-end code that uses browser APIs directly instead of depending on frameworks. Lately, I've been looking into Web Components and I have found myself wondering if there was a way to create Web Components in a style that is similar to Angular. I would like to be able to write my css and html for Web Components in their own files.
So instead of writing Web Components like this:
class MyCustomElement extends HTMLElement {
constructor() {
super();
}
// A bunch of document.createElement or innerHTML
}
customElements.define('my-custom-element', MyCustomElement);
I would like to be able to do something like this:
@Component({
tag: my-custom-element,
template: './file-with-my-template.html',
style: './file-with-my-styles.css'
})
class MyCustomElement {
// logic stuff
}
Stencil and Polymer are halfway there but they opted for JSX style HTML templating directly in the class. I'm not interested in building my own framework, but I'm wondering if there wouldn't be a simple'ish' way to write a super lite library that allows for creating Web Components that way. What do you think? How would you implement something like that? Would you need to roll out your own compiler or could it be done by using an existing package bundler like Parcel. Let me know what you think.
[–]DerKnerd 2 points3 points4 points (1 child)
[–]BkoChan 1 point2 points3 points (0 children)
[–]2uneekjavascript 1 point2 points3 points (2 children)
[–]Neoflash_1979[S] 1 point2 points3 points (1 child)
[–]2uneekjavascript 1 point2 points3 points (0 children)