How to include local javascript on a Gatsby page?

后端 未结 7 553
深忆病人
深忆病人 2020-11-30 07:48

I\'m a total React newbie and I guess there is something fundamental I don\'t quite understand here. A default Gatsby page looks like this. Is there a way to use a local .js

7条回答
  •  醉梦人生
    2020-11-30 08:33

    You can do this very easily with the Gatsby plugin "gatsby-plugin-load-script."

    Simply do this:

    1. Create a folder named static at the root of your gatsby app
    2. Place your script in it
    3. Add the following configuration in gatsby-config.js
        {
          resolve: 'gatsby-plugin-load-script',
          options: {
            src: '/test-script.js', // Change to the script filename
          },
        },
    

提交回复
热议问题