From 2431a57fb351ebcd42f82c9348c3459f7a97a5d7 Mon Sep 17 00:00:00 2001 From: Aaron Carlino Date: Fri, 8 Nov 2019 16:53:25 +1300 Subject: [PATCH] Fix FOUC and add purgecss --- gatsby-browser.js | 5 +++ gatsby-config.js | 11 ++++++- gatsby-ssr.js | 11 +++---- package.json | 1 + src/components/Layout.tsx | 4 --- src/pages/index.tsx | 12 +++++-- yarn.lock | 69 +++++++++++++++++++++++++++++++++++++-- 7 files changed, 96 insertions(+), 17 deletions(-) diff --git a/gatsby-browser.js b/gatsby-browser.js index fdd237d..79a7bb5 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -1,9 +1,14 @@ require("prismjs/themes/prism-okaidia.css"); require("./src/theme/assets/scss/theme.scss"); require('./src/theme/assets/fontawesome/js/all.js'); +const smoothScroll = require('smooth-scroll'); const Layout = require('./src/components/Layout').default; const React = require('react'); +if (typeof window !== "undefined") { + smoothScroll('a[href*="#"]') + } + exports.wrapPageElement = ({ element, props }) => { return {element} }; \ No newline at end of file diff --git a/gatsby-config.js b/gatsby-config.js index 9575593..78b8117 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -46,7 +46,16 @@ module.exports = { options: { // Add any options here }, - }, + }, + { + resolve: `gatsby-plugin-purgecss`, + options: { + printRejected: false, + whitelist: ['.algolia-autocomplete'], + ignore: ['prismjs/','docsearch.js/'], + //purgeOnly : ['components/', '/main.css', 'bootstrap/'], + } + } // this (optional) plugin enables Progressive Web App + Offline functionality // To learn more, visit: https://gatsby.dev/offline // `gatsby-plugin-offline`, diff --git a/gatsby-ssr.js b/gatsby-ssr.js index b17b8fc..366d633 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -1,7 +1,6 @@ -/** - * Implement Gatsby's SSR (Server Side Rendering) APIs in this file. - * - * See: https://www.gatsbyjs.org/docs/ssr-apis/ - */ +const Layout = require('./src/components/Layout').default; +const React = require('react'); -// You can delete this file if you're not using it +exports.wrapPageElement = ({ element, props }) => { + return {element} +}; \ No newline at end of file diff --git a/package.json b/package.json index e13e12a..5290355 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "gatsby-image": "^2.2.30", "gatsby-plugin-manifest": "^2.2.26", "gatsby-plugin-offline": "^3.0.18", + "gatsby-plugin-purgecss": "^4.0.1", "gatsby-plugin-react-helmet": "^3.1.13", "gatsby-plugin-sass": "^2.1.20", "gatsby-plugin-sharp": "^2.2.36", diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 7a94c59..07bab1e 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -1,12 +1,8 @@ import React, { StatelessComponent, useState } from "react"; import Header from './Header'; import Sidebar from './Sidebar'; -import smoothScroll from 'smooth-scroll'; const Layout: StatelessComponent<{}> = ({ children}) => { - if (typeof window !== "undefined") { - smoothScroll('a[href*="#"]') - } const [isToggled, setSidebarOpen] = useState(false); return ( <> diff --git a/src/pages/index.tsx b/src/pages/index.tsx index f2fa284..9c71e62 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,6 +1,12 @@ -import React from 'react' -import { Redirect } from '@reach/router' +import React, { useEffect } from 'react' +import { Redirect, navigate } from '@reach/router' -const IndexPage = () => +const IndexPage = () => { + useEffect(() => { + navigate('/en/4/'); + }, []); + + return
; +} export default IndexPage; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 248420b..3030a0b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3044,6 +3044,15 @@ cliui@^4.0.0: strip-ansi "^4.0.0" wrap-ansi "^2.0.0" +cliui@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-5.0.0.tgz#deefcfdb2e800784aa34f46fa08e06851c7bbbc5" + integrity sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA== + dependencies: + string-width "^3.1.0" + strip-ansi "^5.2.0" + wrap-ansi "^5.1.0" + clone-deep@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/clone-deep/-/clone-deep-4.0.1.tgz#c19fd9bdbbf85942b4fd979c84dcf7d5f07c2387" @@ -5580,6 +5589,15 @@ gatsby-plugin-page-creator@^2.1.28: lodash "^4.17.15" micromatch "^3.1.10" +gatsby-plugin-purgecss@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/gatsby-plugin-purgecss/-/gatsby-plugin-purgecss-4.0.1.tgz#e9b85eb6189aa20fff9f0c2e0c8ce748f64624bb" + integrity sha512-sYh7gm+9dovl+QASrInSXqB2qIMdfGW+Y7+Gum//jYjvktYlFCjGUXD8k/Wiw+CmXaJh8k5avFC23Cot96SS4w== + dependencies: + fs-extra "^8.1.0" + loader-utils "^1.1.0" + purgecss "^1.3.0" + gatsby-plugin-react-helmet@^3.1.13: version "3.1.13" resolved "https://registry.yarnpkg.com/gatsby-plugin-react-helmet/-/gatsby-plugin-react-helmet-3.1.13.tgz#0ba9e2e902ae490b45c898cffece6e17689da9ee" @@ -5937,6 +5955,11 @@ get-caller-file@^1.0.1: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" integrity sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w== +get-caller-file@^2.0.1: + version "2.0.5" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" + integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== + get-own-enumerable-property-symbols@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.1.tgz#6f7764f88ea11e0b514bd9bd860a132259992ca4" @@ -10179,7 +10202,7 @@ postcss@^6.0.0, postcss@^6.0.1, postcss@^6.0.23, postcss@^6.0.9: source-map "^0.6.1" supports-color "^5.4.0" -postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.11, postcss@^7.0.18, postcss@^7.0.21, postcss@^7.0.5: +postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.11, postcss@^7.0.14, postcss@^7.0.18, postcss@^7.0.21, postcss@^7.0.5: version "7.0.21" resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.21.tgz#06bb07824c19c2021c5d056d5b10c35b989f7e17" integrity sha512-uIFtJElxJo29QC753JzhidoAhvp/e/Exezkdhfmt8AymWT6/5B7W1WmponYWkHk2eg6sONyTch0A3nkMPun3SQ== @@ -10424,6 +10447,16 @@ punycode@^2.1.0: resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== +purgecss@^1.3.0: + version "1.4.1" + resolved "https://registry.yarnpkg.com/purgecss/-/purgecss-1.4.1.tgz#d362e63eb1ed9dd1fa1554b9fd7accb8d54e56dc" + integrity sha512-5jONV/D/3nfa+lC425+LA+OWe5/LDn4a79cac+TnzJq3VczwnWlpIDdW275hHsGhkzIlqATQsYFLW7or0cSwNQ== + dependencies: + glob "^7.1.3" + postcss "^7.0.14" + postcss-selector-parser "^6.0.0" + yargs "^14.0.0" + q@^1.1.2: version "1.5.1" resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7" @@ -11053,6 +11086,11 @@ require-main-filename@^1.0.1: resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" integrity sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE= +require-main-filename@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" + integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== + requires-port@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" @@ -12066,7 +12104,7 @@ string-width@^1.0.1, string-width@^1.0.2: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" -string-width@^3.0.0: +string-width@^3.0.0, string-width@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w== @@ -13628,7 +13666,7 @@ wrap-ansi@^2.0.0: string-width "^1.0.1" strip-ansi "^3.0.1" -wrap-ansi@^5.0.0: +wrap-ansi@^5.0.0, wrap-ansi@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-5.1.0.tgz#1fd1f67235d5b6d0fee781056001bfb694c03b09" integrity sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q== @@ -13788,6 +13826,14 @@ yargs-parser@^11.1.1: camelcase "^5.0.0" decamelize "^1.2.0" +yargs-parser@^15.0.0: + version "15.0.0" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-15.0.0.tgz#cdd7a97490ec836195f59f3f4dbe5ea9e8f75f08" + integrity sha512-xLTUnCMc4JhxrPEPUYD5IBR1mWCK/aT6+RJ/K29JY2y1vD+FhtgKK0AXRWvI262q3QSffAQuTouFIKUuHX89wQ== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + yargs-parser@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-5.0.0.tgz#275ecf0d7ffe05c77e64e7c86e4cd94bf0e1228a" @@ -13820,6 +13866,23 @@ yargs@12.0.5, yargs@^12.0.5: y18n "^3.2.1 || ^4.0.0" yargs-parser "^11.1.1" +yargs@^14.0.0: + version "14.2.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-14.2.0.tgz#f116a9242c4ed8668790b40759b4906c276e76c3" + integrity sha512-/is78VKbKs70bVZH7w4YaZea6xcJWOAwkhbR0CFuZBmYtfTYF0xjGJF43AYd8g2Uii1yJwmS5GR2vBmrc32sbg== + dependencies: + cliui "^5.0.0" + decamelize "^1.2.0" + find-up "^3.0.0" + get-caller-file "^2.0.1" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^3.0.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^15.0.0" + yargs@^7.0.0: version "7.1.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-7.1.0.tgz#6ba318eb16961727f5d284f8ea003e8d6154d0c8"