[英]Import svelte html file into js file using rollup
Js file: js文件:
import template from './Template.html';
class VacationListForCompany extends HTMLElement {
constructor() {
super();
const root = this.attachShadow({mode:'open'});
const t = new template({ target: root });
}
}
window.customElements.define("vacation-list-for-company",
VacationListForCompany);
Svelte/HTML file Svelte / HTML文件
<h1> This is from SVELTE </h1>
<script>
export default {
};
</script>
And in my Rollupfile import svelte from 'rollup-plugin-svelte'; 在我的Rollupfile中,从'rollup-plugin-svelte'导入svelte;
export default {
input: 'Widgets/VacationListForCompany/widget.js',
output: {
format: 'iife',
file: 'dist/vacationlistforcompany.js',
},
plugins: [
svelte({ include:'*.html'})
],
};
Seems like rollup is not able to generate svelte component on import.. Am I missunderstanding something here? 好像汇总不能在导入时生成苗条的组件。我在这里误解了吗?
By default, Svelte compiles the HTML file into a Svelte component. 默认情况下,Svelte将HTML文件编译为Svelte组件。 See the docs for the Svelte component API . 请参阅Svelte组件API的文档 。
To generate a custom element instead, you need to pass customelement: true
to the compiler (in your case, by setting it in the options passed to rollup-plugin-svelte
). 要生成一个定制元素,您需要将customelement: true
传递给编译器(在您的情况下,通过在传递给rollup-plugin-svelte
的选项中进行设置)。 See PR 797 参见PR 797
It was of cource an error from my side... the 从我这边说来是错误的...
svelte({ include:'*.html'})
for some reason is misspelled, removing this made it work.. 由于某种原因拼写错误,将其删除即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.