Skip to content

Instantly share code, notes, and snippets.

@gdhardy1
gdhardy1 / conditional-gatsby-config.js
Created November 1, 2021 17:10
Conditionally include a gatsby-plugin-gatsby-cloud.js
/**
* Configure your Gatsby site with this file.
*
* See: https://www.gatsbyjs.com/docs/gatsby-config/
*/
module.exports = {
/* Your site config here */
plugins: [
process.env.GATSBY_CLOUD && "gatsby-plugin-gatsby-cloud",
@gdhardy1
gdhardy1 / wordpress-preview-optimization.js
Last active August 24, 2021 14:29
PREVIEW_OPTIMIZATION Config
module.exports = {
plugins: [
{
resolve: `gatsby-source-wordpress`,
options: {
url: process.env.WORDPRESS_GRAPHQL_ENDPOINT,
presets: [
{
presetName: `PREVIEW_OPTIMIZATION`,
useIf: () =>
@gdhardy1
gdhardy1 / gatsby-ssr.js
Created May 5, 2021 17:46
Setting head components in gatsby
const React = require("react")
exports.onRenderBody = ({ setHeadComponents }) => {
setHeadComponents([
<link
href="https://cloud.typography.com/path/to/your/file.css"
rel="stylesheet"
type="text/css"
media="print"
@gdhardy1
gdhardy1 / allowCapsPascalCaseLinting.js
Created April 6, 2021 13:57
allow all caps for eslint-plugin-react PascalCase warning
// .eslintrc.js
module.exports = {
globals: {
__PATH_PREFIX__: true,
},
extends: `react-app`,
rules:{
"react/jsx-pascal-case": [1, {allowAllCaps: true}]
}
@gdhardy1
gdhardy1 / silenceCssOrderWarning.js
Created April 6, 2021 13:39
Silence mini-css-extract-plugin warning about css order conflict
// gatsby-node.js
exports.onCreateWebpackConfig = ({ stage, actions, getConfig, rules }) => {
const config = getConfig();
const miniCssExtractPlugin = config.plugins.find(
(plugin) => plugin.constructor.name === 'MiniCssExtractPlugin'
);
if (miniCssExtractPlugin) {
miniCssExtractPlugin.options.ignoreOrder = true;
}
@gdhardy1
gdhardy1 / gatsbyReporter.js
Created March 25, 2021 14:33
Gatsby Reporter
exports.onPostBuild = async ({ reporter }) => {
fs.copyFile(`./firebase.json`, `./public/firebase.json`, (err) => {
if (err) {
reporter.error(
"An error occured when copying firebase.json to public dir",
err
);
}
});
};
@gdhardy1
gdhardy1 / gatsbyRetryGraphQL.js
Last active December 22, 2020 22:50
Gatsby Retry GraphQL Query
// Composing Apollo links
// https://www.apollographql.com/docs/link/composition/
// for apollo-retry-link info:
// - https://www.apollographql.com/docs/link/links/retry/
// - https://www.youtube.com/watch?v=bv74TcKb1jw
// for gatsby-source-grapql config info:
// see https://www.gatsbyjs.com/plugins/gatsby-source-graphql/
@gdhardy1
gdhardy1 / proxyExample.js
Created November 17, 2020 23:20
JS Proxy
// Example of Proxy in JS
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
class Target{
log(msg){
console.log(msg)
return msg
}
}