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?
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 .
The Image CDN is Gatsby Cloud's content delivery network service that enables websites to run faster by loading resources from edge servers.
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).
[ 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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With