视频标签与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"/>
我研究并发现了
Web Pack配置
web pack configuration
使其成为可能,但我不知道如何将其引入create-react-app项目。
to make this possible but i can't figure out how to introduce it to create-react-app project.
我无法为我的视频进行云托管,因为我也需要移动版本的视频。任何人都可以帮忙吗?
I can't go cloud hosting for my videos because i need it on mobile version as well.please can anyone help?
推荐答案
您要使用的语法(动态 import()
)为用于代码拆分,不适用于添加文件。
我不确定为什么要查找Webpack配置,因为开箱即用的支持。
The syntax you’re trying to use (dynamic import()
) is for code splitting, not for adding files.
I’m not sure why you were looking for Webpack configuration, as this is supported out of the box.
请尊重官方文档,说明了如何导入资产:
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" />;
}
这篇关于视频标签与create-react-app项目反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!