2017-10-09 62 views
0

js文件:導入苗條的html文件到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); 

斯維爾特/ HTML文件

<h1> This is from SVELTE </h1> 
<script> 
    export default { 
    }; 
</script> 

在我Rollupfile 進口從 '彙總 - 插件 - 苗條' 身材苗條;

export default { 
    input: 'Widgets/VacationListForCompany/widget.js', 
    output: { 
     format: 'iife', 
     file: 'dist/vacationlistforcompany.js', 
    }, 
    plugins: [ 
    svelte({ include:'*.html'}) 
    ], 
}; 

enter image description here

好像彙總是不能夠產生對進口苗條組件.. 我在這裏missunderstanding的東西嗎?

+0

順便說一句,我使用Visual Studio – PEtter

回答

0

默認情況下,Svelte將HTML文件編譯爲Svelte組件。 See the docs for the Svelte component API

要生成自定義元素,您需要將customelement: true傳遞給編譯器(在您的情況下,通過將其設置爲傳遞給rollup-plugin-svelte的選項)。 See PR 797

+0

Thaks爲你的答案,但是...這不是我的queston :)我意識到這一點,但我想創建我自己的自定義元素..只是使用苗條作爲內部「引擎」來產生它。 – PEtter

+0

從'./Template.html'導入模板; < - 這是失敗的行 – PEtter

0

這是五言從我身邊一個錯誤的......在

svelte({ include:'*.html'}) 

由於某種原因被拼錯,除去這使得它工作..

+0

'include'應該是glob模式 - 要捕獲所有的HTML文件,它應該是'**/*。html'。 (但是刪除'include'完全一樣,因爲這是默認設置。) –