我们有一个新的基于Lit-element的项目,我们正在考虑使诸如动态导入之类的某些事情自动化。我们已经通过实现两个主要部分来做到这一点:
component-tag: () => import('path')
的键值对的导出写入新文件中现在主要问题是:
谢谢
// generated file
export default {
"tag-elem-one": () => import("/src/components/tag-elem-one.js"),
"tag-elem-two": () => import("/src/components/tag-elem-two.js"),
};
// Checker
////////////////////
const attachShadow = HTMLElement.prototype.attachShadow
HTMLElement.prototype.attachShadow = function (option) {
const sh = attachShadow.call(this, option);
this.mutationObserver = new MutationObserver((mutations) => {
mutations.forEach(mutation => {
if (mutation.addedNodes.length) {
mutation.addedNodes.forEach(addedNode => {
if (addedNode.nodeName.includes('-')) {
const tag = addedNode.nodeName.toLowerCase();
importTag(tag)
}
importTagsInNodeChildren(addedNode)
})
}
})
});
this.mutationObserver.observe(this.shadowRoot, {
childList: true,
subtree: true
});
return sh;
};