Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gatsby with CDN reference

I'm trying to get bootstrap.css and Google fonts CDNs working in my Gatsby project.

There is no HTML file; just JavaScript files.

For bootstrap, I can npm install bootstrap and then import the min.css from that.

Trying to figure out how to get Amatic SC font from Google fonts; I have npm installed google-fonts-webpack-plugin.

I am using gatsby-node.js by adding:

const GoogleFontsPlugin = require("google-fonts-webpack-plugin")

exports.modifyWebpackConfig = ({ config, stage }) => {

    config.plugin("google-fonts-webpack-plugin",new GoogleFontsPlugin(
        {
            fonts: [
                { family: "Amatic SC" }
            ]
        }
    ),null)

};

However, I get the error below;

Invalid 'constructor' parameter. You must provide either a function or null

What am I doing wrong and how can I fix it?

Is there a way of referencing a CDN directly so rather than npm installing bootstrap, I could just reference its latest version?

like image 228
user2047485 Avatar asked May 02 '18 12:05

user2047485


People also ask

How do you use CDN in The Great Gatsby?

In the component where you need it, load the package via CDN using a <script /> tag. To embed your script, you can: Include it in a custom component as needed using react-helmet . Add the script tag directly by using Gatsby's setHeadComponents in the onRenderBody API in gatsby-ssr .

Is Gatsby a CDN?

The Image CDN is Gatsby Cloud's content delivery network service that enables websites to run faster by loading resources from edge servers.

Does Gatsby support server-side rendering?

As already mentioned, Gatsby always supported SSG and client-side rendering. Now, two other rendering options are available: Deferred Static Generation (DSG) and Server-Side rendering (SSR).

Is Gatsby a full stack framework?

[ Also on InfoWorld: The best open source software of 2021 ] js or SvelteKit, Gatsby is purely a front-end framework, not a full-stack one. Therefore, Node. js is required for development, but not for deployment. For that, Gatsby supports several click-to-deploy platforms including Netlify and Gatsby Cloud.


1 Answers

You can include the font using typeface-amatic-sm from NPM, and in your JS do:

import 'typeface-amatic-sc'

Otherwise, can include scripts it in your </head> using helmet like:

<Helmet>    
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
</Helmet>
like image 50
rebelliard Avatar answered Nov 02 '22 20:11

rebelliard