gatsby - How to add local script file to gatsby
问题描述
I need add my local javascript file to my gatsby project. The file is a library. What I tried to do:
1) put myscript.js
to ./src
and import it in ./src/html.js
file as import from './myscript.js';
2) put myscript.js
to ./src
and import it in ./src/html.js
file as <script type='text/javascript' src="./myscript.js"/>
3) put myscript.js
to ./public
and import it in both ways
But none of this works. Please, tell me how to do it?
解决方案
您要添加什么?什么样的图书馆?您不应该将脚本添加到 Html 文件中(尽管这是可能的)如果您想使用外部库,那么您可以通过 npm 或 yarn 安装它并将其导入您的组件中。
在这里查看添加自定义脚本到 gatsby 项目中的 Html 文件:add script to Html in gatsby
您还可以在此处查看使用不同方法插入脚本的详细信息:更多方法
编辑:
您可以尝试使用静态文件夹。在这里检查这个答案:使用静态文件夹 gatsby
推荐阅读
- python - 使用 Python 暴力破解我的投影仪红外遥控器
- c++ - 错误:非静态数据成员“Application::ApplicationConstructor”的使用无效
- javascript - 使用 vue-axios 在浏览器控制台上显示数据
- hadoop - 有没有办法使用 Prometheus 监控 Hadoop 指标?
- python - 对于大小为 38 的轴 1,索引 38 超出范围 - Sklearn
- meteor - Rocketchat 生产级,与 Meteor Galaxy 一起部署仍然是一个不错的选择?
- python-3.x - 用 Python 洗牌
- sql - Oracle 数据库无符号整数
- java - Spring rest api为什么在rest api调用的响应中数据类型发生变化
- rust - 如何创建一个 Rc
> 自可变引用?