svelte - (!) 插件 slim : No custom element 'tag' option was specified

标签 svelte svelte-component

我尝试将 Svelte 组件编译为 Web 组件。

  • 添加了选项 <svelte:options tag="date-picker" immutable={true}/>
  • 已添加 customElement: true汇总到 plugins: [ svelte()
  • 运行 npm run build

  • 但我不断收到消息:

    (!) Plugin svelte: No custom element 'tag' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. . To hide this warning, use



    我究竟做错了什么?

    我的 index.js文件:
    export { default as default } from './DatePicker.svelte';
    
    DatePicker.svelte文件:
    <svelte:options tag="date-picker" immutable={true}/>
    
    <script>
      /* code */
    

    汇总文件:
    import svelte from 'rollup-plugin-svelte';
    import resolve from '@rollup/plugin-node-resolve';
    import pkg from './package.json';
    
    const name = pkg.name
        .replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3')
        .replace(/^\w/, m => m.toUpperCase())
        .replace(/-\w/g, m => m[1].toUpperCase());
    
    export default {
        input: 'src/index.js',
        output: [
            { file: pkg.module, 'format': 'es' },
            { file: pkg.main, 'format': 'umd', name }
        ],
        plugins: [
            svelte({
                customElement: true
            }),
            resolve()
        ]
    };
    

    似乎如果您的项目由单个组件组成,则不会出现该消息。请参阅此处的问题:

    https://github.com/sil-vio/svelte-web-components/issues/2

    最佳答案

    您需要嵌套 customElement选择更深一层,像这样

      plugins: [
        svelte({
          compilerOptions: {
            customElement: true,
    
    您可以在 rollup-plugin-svelte 文档中看到这一点:https://github.com/sveltejs/rollup-plugin-svelte#usage

    关于svelte - (!) 插件 slim : No custom element 'tag' option was specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60719828/

    相关文章:

    javascript - 加密缺少全局变量名

    Svelte:使用基于模块上下文变量的响应式(Reactive)语句

    javascript - 在 typescript svelte 中导入别名 svelte 组件

    svelte - 在相同的 Javascript 上下文中创建带有附加 svelte 组件的窗口

    svelte - 是否可以使用 Svelte 跨多个组件绑定(bind)相同的变量?

    svelte - 更新数组中对象的正确方法是什么?

    events - slim ,在 :click event inside each block triggers on page load

    javascript - 如何使用 Svelte 传播 Prop

    javascript - 如何检测 AdSense 是否在 JavaScript 中加载了广告?

    javascript - 对象中的计算值 |斯韦尔特