I have project with structure that looks like this
-client
----index.html
----index.ts
-core
----controls
--------myControl.html
--------myControl.ts
----css
--------common.css
myControl.html contains definition of custom component that is registered via shadow dom. in its template imports common.css that is part of "core" library:
<template id="t">
<style>
@import url('../css/common.css');
....
</style>
....
</template>
<script>
(function() {
var importDoc = document.currentScript.ownerDocument; // importee
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function()
{
// get template in import
var template = importDoc.querySelector('#t');
// import template into
var clone = document.importNode(template.content, true);
var root = this.createShadowRoot();
root.appendChild(clone);
var control = this;
System.import('core/controls/myControl').then(function(m)
{
var t = new m.myControl(control.shadowRoot);
});
};
document.registerElement('my-control', {prototype: proto});
})();
</script>
Now when I use my-control on the index.html the browser complains that it cannot import common.css. Because it search for it using path relative to index.html, not relative to its originall location. I understand this is logical because we have created shadow dom from the script that runs in context of index.html.
My question is: how should I develop my-control custom component that is part of 'core' library that can be reused/distributed in different places and still correctly reference resources like css/images/etc that are also part of the 'core' library.
Thanks in advance.