Exporting Separate Custom Elements from Svelte Components

强颜欢笑 提交于 2020-06-26 12:37:39

问题


I'm trying to find out if it's possible to export each Svelte component as a separate Custom Element (with Shadow DOM) in its own js file (with imports for any child elements - i.e. dependencies aren't included in the same file). Is it even possible?

Thanks


回答1:


I'm assuming you're using rollup and rollup-plugin-svelte

the way to do it is to use code splitting. You can define the inputs separately and that will create individual outputs. Instead of using a file name output, you would use an output dir.

example:

import svelte from 'rollup-plugin-svelte';

export default [
    {
        input: ['src/main-a.js', 'src/main-b.js'],
        output: {
            dir: 'public/module',
            format: 'es',
            sourcemap: true
        },
        plugins: [svelte()],
        experimentalCodeSplitting: true,
        experimentalDynamicImport: true
    },
];

source/reference/example: https://github.com/Rich-Harris/rollup-svelte-code-splitting



来源:https://stackoverflow.com/questions/56356230/exporting-separate-custom-elements-from-svelte-components

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!