简体   繁体   English

视频标签与create-react-app项目反应

[英]Video tag on react with create-react-app project

I am having problem adding a local video to my project as 我在将本地视频添加到我的项目时遇到问题

<video src={import(src/assets/abc.mp4)} type="video/mp4"/>

I have researched and found out about 我已经研究发现

web pack configuration Web Pack配置

to make this possible but i can't figure out how to introduce it to create-react-app project. 使之成为可能,但我不知道如何将其引入create-react-app项目。

I can't go cloud hosting for my videos because i need it on mobile version as well.please can anyone help? 我不能将视频托管在云中,因为我也需要移动版本的视频。任何人都可以帮忙吗?

The syntax you're trying to use (dynamic import() ) is for code splitting , not for adding files . 您尝试使用的语法(动态import() )用于代码拆分 ,而不是用于添加文件
I'm not sure why you were looking for Webpack configuration, as this is supported out of the box. 我不确定您为什么要寻找Webpack配置,因为开箱即用的支持。

Please follow the official documentation that explains how to import assets: 请遵循解释如何导入资产的官方文档

// Assuming abc.mp4 is in the same folder as this component
import myVideo from './abc.mp4';
// This will become a string with the path to the video at build time

// Your component definition
export default function MyComponent() {
  return <video src={myVideo} type="video/mp4" />;
}

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

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