Javascript 禁用网页3中的树抖动
如何禁用网页3中的树抖动 我正在尝试在完全本地的web组件中构建web应用程序,我依靠克隆模板元素并附加innerHTML来呈现其中的任何子组件。但是,由于webpack没有看到我在javascript中使用子组件,因此它没有绑定适当的文件,因此从未定义web组件Javascript 禁用网页3中的树抖动,javascript,typescript,webpack,ecmascript-6,web-component,Javascript,Typescript,Webpack,Ecmascript 6,Web Component,如何禁用网页3中的树抖动 我正在尝试在完全本地的web组件中构建web应用程序,我依靠克隆模板元素并附加innerHTML来呈现其中的任何子组件。但是,由于webpack没有看到我在javascript中使用子组件,因此它没有绑定适当的文件,因此从未定义web组件 import MyComponent from './my-component'; let template = document.createElement('template'); template.innerHTML = ` &
import MyComponent from './my-component';
let template = document.createElement('template');
template.innerHTML = `
<h1>My Web App</h1>
<my-component></my-component>
`;
export default class WebApp extends HTMLElement {
constructor () {
super();
let shadowRoot = this.attachShadow({mode: 'open'});
shadowRoot.appendChild(template.content.cloneNode(true));
}
}
从“/my component”导入MyComponent;
让template=document.createElement('template');
template.innerHTML=`
我的网络应用
`;
导出默认类WebApp扩展HtmleElement{
构造函数(){
超级();
让shadowRoot=this.attachShadow({mode:'open'});
appendChild(template.content.cloneNode(true));
}
}
如果我包括一个调用,比如let myComponent=new myComponent()代码>,我可以看到webpack最终绑定了导入,所以我相信这是因为组件是在模板字符串中定义的
谢谢。原来不是Webpack删除了捆绑包,而是typescript编译器。Typescript将“elide”导入,因为它没有被使用,但是将import语句从“/my component”更改为“import MyComponent”代码>导入到<代码>导入'/my component'代码>强制typescript包含它
谢谢你@cartant 原来不是Webpack删除了捆绑包,而是typescript编译器。Typescript将“elide”导入,因为它没有被使用,但是将import语句从“/my component”更改为“import MyComponent”代码>导入到<代码>导入'/my component'代码>强制typescript包含它
谢谢你@cartant 我的理解是,做这件事的不是网页;这是打字稿。使用类似这样的导入:import'/my component'代码>在中搜索“仅副作用”。先生,你是个天才。Webpack不是罪魁祸首。我的理解是,不是Webpack在做这件事;这是打字稿。使用类似这样的导入:import'/my component'代码>在中搜索“仅副作用”。先生,你是个天才。Webpack不是罪魁祸首。