首页 > 解决方案 > 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?

标签: gatsby

解决方案


您要添加什么?什么样的图书馆?您不应该将脚本添加到 Html 文件中(尽管这是可能的)如果您想使用外部库,那么您可以通过 npm 或 yarn 安装它并将其导入您的组件中。

在这里查看添加自定义脚本到 gatsby 项目中的 Html 文件:add script to Html in gatsby

您还可以在此处查看使用不同方法插入脚本的详细信息:更多方法

编辑:

您可以尝试使用静态文件夹。在这里检查这个答案:使用静态文件夹 gatsby


推荐阅读