简体   繁体   English

Vue.js Vite 构建错误<video><source>标签</video>

[英]Vue.js Vite Build Error with <video><source> tags

I'm working on a Vue 3 app and am trying to swap out a static image for a video and it's throwing a我正在开发一个 Vue 3 应用程序,并试图将 static 图像换成视频,它正在抛出一个

[vite] Build errored out.
Error: Unexpected character '' (Note that you need plugins to import files that are not JavaScript) at error (/myapp/node_modules/rollup/dist/shared/rollup.js:5275:30)
...

This builds (not that you'd use an image but just to show):这构建(不是你会使用图像,而只是为了显示):

<video class="w-2/3 xs:w-full" controls="controls" name="Video Name">
     <source src="/images/my_image.png">
</video>

This does not:这不会:

<video class="w-2/3 xs:w-full" controls="controls" name="Video Name">
     <source src="/images/my_movie.mov">
</video>

I'm new to Vite and am trying to understand why it seems to be wanting to import the video from the HTML tag.我是 Vite 的新手,我想了解为什么它似乎想要从 HTML 标签导入视频。

Add poster="/images/my_image.png" to the video tag.添加 poster="/images/my_image.png" 到视频标签。 Like this;像这样;

<video poster=“/images/my_image.png” … <视频海报=“/images/my_image.png” ...

Otherwise, you can't put an image into the source tag.否则,您无法将图像放入源标签。

This seems like a bug (perhaps in @vue/compiler-sfc , which compiles the templates and resolves the src URLs there).这似乎是一个错误(可能在@vue/compiler-sfc中,它编译模板并在那里解析src URL)。 I'm not sure why Vite (or the template compliler) is unable to handle the .mov extension for src , but a workaround is to bind a literal string:我不确定为什么 Vite(或模板编译器)无法处理src.mov扩展名,但一种解决方法是绑定文字字符串:

<video class="w-2/3 xs:w-full" controls="controls" name="Video Name">
  <!-- BEFORE -->
  <!--<source src="/images/my_movie.mov">-->

  <source :src="`/images/my_movie.mov`">
</video>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM