amazon-web-services - 在页面构建时将资产从 CDN 导入 Gatsby
问题描述
我想将资产(视频)从 CDN (AWS CloudFront) 导入 Gatsby 中的特定页面。我不知道该怎么做。
我尝试import
在页面顶部添加一个引用资产链接的语句,即:http://[refId].cloudfront.net/myVideo.mp4。当我这样做并运行时gatsby develop
,我得到This dependency was not found
并引用了链接。
当我运行时gatsby build
,我收到以下错误:
错误:./src/pages/index.js 未找到模块:错误:无法解析'C:\Users\David\Documents\wa 中的' http://[refId].cloudfront.net/myVideo.mp4 ' mp\www\greystone\src\pages' 解析'C:\Users\David\Documents\wamp\www\greystone\src\pages' 中的 ' http://[refId].cloudfront.net/myVideo.mp4 ' 已解析请求是使用描述文件的模块:C:\Users\David\Documents\wamp\www\greystone\package.json(相对路径:./src/pages)字段“浏览器”不包含有效的别名配置解析为模块 C:\Users\David\Documents\wamp\www\greystone\src\pages\node_modules 不存在或不是目录
所以 Gatsby 正试图将导入解读为一个模块,它出现了。
我在 Gatsby Docs, Importing Assets Directly Into Files中找到了这个页面,但是没有提到如何使用 CDN 来做到这一点。
导入链接本身,当放置在浏览器地址栏中时有效,但当试图以这种方式将资产导入页面时,Gatsby 无法构建/编译。
import myVideo from 'http://[refId].cloudfront.net/myVideo.mp4'
export default (props) => (
...
<video src={myVideo}></video>
...
)
我希望 URL 被转译/编译成静态 HTML。
解决方案
也许您可以直接在组件中使用 url:
export default (props) => (
...
<video src="http://[refId].cloudfront.net/myVideo.mp4"></video>
...
)
如果您想存储视频并与 Gatsby 一起提供,请createRemoteFileNode
查看gatsby-source-filesystem
.
推荐阅读
- vue.js - Electron-vue 创建新窗口
- python-3.x - 在 Windows 10 上带有上下文管理器的 Python 临时文件导致 PermissionError:[Errno 13]
- angular - 如何构建结合了 Angular 和 Spring Boot 应用程序的 Docker 映像?
- php - 使用 PHP 更新 sql 表中的字段
- javascript - JS:实例化变量无法识别输入值
- xaml - 非根对象中的 XAML 事件处理程序
- java - Axon - MySql 的 JPA 事件存储
- javascript - 具有多个变量的三元运算符
- javascript - 显示一个由于数据库请求(门户字段)
- html - 我的问题是将字体上传到网站