Skip to content

Commit

Permalink
feat: Add bundle-analyzer and lazy-load react-live (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts committed Jul 9, 2020
1 parent 9673c72 commit 667fd33
Show file tree
Hide file tree
Showing 25 changed files with 2,380 additions and 5,749 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ module.exports = {
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/ban-ts-ignore": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/ban-ts-comment": 0,
"no-console": [`warn`, { allow: [`warn`] }],
"spaced-comment": [2, `always`, { exceptions: [`-`, `+`], markers: [`/`] }],
"no-use-before-define": 0,
"linebreak-style": 0,
"consistent-return": 0,
import: 0,
camelcase: 1,
"import/no-unresolved": 0,
"func-names": 0,
"import/no-extraneous-dependencies": 0,
Expand Down
12 changes: 11 additions & 1 deletion examples/cara/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require(`dotenv`).config({
path: `.env`,
})

const shouldAnalyseBundle = process.env.ANALYSE_BUNDLE

module.exports = {
siteMetadata: {
// You can overwrite values here that are used for the SEO component
Expand Down Expand Up @@ -47,5 +49,13 @@ module.exports = {
},
`gatsby-plugin-offline`,
`gatsby-plugin-netlify`,
],
shouldAnalyseBundle && {
resolve: `gatsby-plugin-webpack-bundle-analyser-v2`,
options: {
analyzerMode: `static`,
reportFilename: `_bundle.html`,
openAnalyzer: false,
},
},
].filter(Boolean),
}
1 change: 1 addition & 0 deletions examples/cara/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"gatsby-plugin-manifest": "^2.2.6",
"gatsby-plugin-netlify": "^2.1.6",
"gatsby-plugin-offline": "^2.2.7",
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.10",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
Expand Down
12 changes: 11 additions & 1 deletion examples/emilia/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require(`dotenv`).config({
path: `.env`,
})

const shouldAnalyseBundle = process.env.ANALYSE_BUNDLE

module.exports = {
siteMetadata: {
siteTitleAlt: `Emilia - Gatsby Starter Portfolio`,
Expand Down Expand Up @@ -45,5 +47,13 @@ module.exports = {
},
`gatsby-plugin-offline`,
`gatsby-plugin-netlify`,
],
shouldAnalyseBundle && {
resolve: `gatsby-plugin-webpack-bundle-analyser-v2`,
options: {
analyzerMode: `static`,
reportFilename: `_bundle.html`,
openAnalyzer: false,
},
},
].filter(Boolean),
}
1 change: 1 addition & 0 deletions examples/emilia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"gatsby-plugin-netlify": "^2.1.11",
"gatsby-plugin-offline": "^3.0.1",
"gatsby-plugin-sitemap": "^2.2.7",
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.10",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
Expand Down
12 changes: 11 additions & 1 deletion examples/emma/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require(`dotenv`).config({
path: `.env`,
})

const shouldAnalyseBundle = process.env.ANALYSE_BUNDLE

module.exports = {
siteMetadata: {
siteTitleAlt: `Emma - Gatsby Starter Portfolio`,
Expand Down Expand Up @@ -45,5 +47,13 @@ module.exports = {
},
`gatsby-plugin-offline`,
`gatsby-plugin-netlify`,
],
shouldAnalyseBundle && {
resolve: `gatsby-plugin-webpack-bundle-analyser-v2`,
options: {
analyzerMode: `static`,
reportFilename: `_bundle.html`,
openAnalyzer: false,
},
},
].filter(Boolean),
}
1 change: 1 addition & 0 deletions examples/emma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"gatsby-plugin-netlify": "^2.1.6",
"gatsby-plugin-offline": "^2.2.7",
"gatsby-plugin-sitemap": "^2.2.7",
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.10",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
Expand Down
16 changes: 15 additions & 1 deletion examples/graphql-playground/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
require(`dotenv`).config({
path: `.env`,
})

const shouldAnalyseBundle = process.env.ANALYSE_BUNDLE

module.exports = {
plugins: [
{
Expand All @@ -6,5 +12,13 @@ module.exports = {
options: {},
},
`gatsby-plugin-netlify`,
],
shouldAnalyseBundle && {
resolve: `gatsby-plugin-webpack-bundle-analyser-v2`,
options: {
analyzerMode: `static`,
reportFilename: `_bundle.html`,
openAnalyzer: false,
},
},
].filter(Boolean),
}
1 change: 1 addition & 0 deletions examples/graphql-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@lekoarts/gatsby-theme-graphql-playground": "^1.1.11",
"gatsby": "^2.20.36",
"gatsby-plugin-netlify": "^2.1.23",
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.10",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
Expand Down
12 changes: 11 additions & 1 deletion examples/minimal-blog/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require(`dotenv`).config({
path: `.env`,
})

const shouldAnalyseBundle = process.env.ANALYSE_BUNDLE

module.exports = {
siteMetadata: {
siteTitleAlt: `Minimal Blog - Gatsby Theme`,
Expand Down Expand Up @@ -66,5 +68,13 @@ module.exports = {
},
`gatsby-plugin-offline`,
`gatsby-plugin-netlify`,
],
shouldAnalyseBundle && {
resolve: `gatsby-plugin-webpack-bundle-analyser-v2`,
options: {
analyzerMode: `static`,
reportFilename: `_bundle.html`,
openAnalyzer: false,
},
},
].filter(Boolean),
}
1 change: 1 addition & 0 deletions examples/minimal-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"gatsby-plugin-netlify": "^2.1.3",
"gatsby-plugin-offline": "^2.2.4",
"gatsby-plugin-sitemap": "^2.2.19",
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.10",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
Expand Down
12 changes: 11 additions & 1 deletion examples/specimens/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// eslint-disable-next-line global-require
const remarkPlugins = [require(`remark-slug`)]

const shouldAnalyseBundle = process.env.ANALYSE_BUNDLE

module.exports = {
siteMetadata: {
siteTitle: `Specimens for Design Systems - @lekoarts/gatsby-theme-specimens`,
Expand Down Expand Up @@ -60,5 +62,13 @@ module.exports = {
},
`gatsby-plugin-offline`,
`gatsby-plugin-netlify`,
],
shouldAnalyseBundle && {
resolve: `gatsby-plugin-webpack-bundle-analyser-v2`,
options: {
analyzerMode: `static`,
reportFilename: `_bundle.html`,
openAnalyzer: false,
},
},
].filter(Boolean),
}
2 changes: 2 additions & 0 deletions examples/specimens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@lekoarts/gatsby-theme-specimens": "^2.2.8",
"@loadable/component": "^5.13.1",
"@mdx-js/mdx": "^1.5.9",
"@theme-ui/presets": "^0.3.0",
"gatsby": "^2.20.36",
Expand All @@ -28,6 +29,7 @@
"gatsby-plugin-offline": "^2.2.7",
"gatsby-plugin-react-helmet": "^3.1.4",
"gatsby-plugin-theme-ui": "^0.3.0",
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.10",
"gatsby-source-filesystem": "^2.1.10",
"mdx-utils": "^0.2.0",
"prism-react-renderer": "^1.1.0",
Expand Down
29 changes: 21 additions & 8 deletions examples/specimens/src/components/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from "react"
import Highlight, { defaultProps } from "prism-react-renderer"
import theme from "prism-react-renderer/themes/vsDark"
import { LiveProvider, LiveEditor, LiveError, LivePreview } from "react-live"
import loadable from "@loadable/component"
import { useMDXScope } from "gatsby-plugin-mdx/context"
import { useMDXComponents } from "@mdx-js/react"
import { css } from "@emotion/core"
Expand All @@ -19,6 +19,20 @@ const badgeStyle = {
letterSpacing: `0.05em`,
}

const LazyLiveProvider = loadable(async () => {
const Module = await import(`react-live`)
const { LiveProvider, LiveEditor, LiveError, LivePreview } = Module
return (props) => (
<LiveProvider {...props}>
<div css={css(badgeStyle)}>Editor</div>
<LiveEditor css={css({ marginBottom: `1rem`, borderRadius: `0.25rem` })} />
<LiveError />
<div css={css(badgeStyle)}>Preview</div>
<LivePreview css={css({ marginBottom: `3rem` })} />
</LiveProvider>
)
})

const Code = ({ codeString, language, live, noInline }) => {
const imported = useMDXScope()
const defined = useMDXComponents()
Expand All @@ -27,13 +41,12 @@ const Code = ({ codeString, language, live, noInline }) => {

if (live) {
return (
<LiveProvider code={codeString} theme={theme} noInline={noInline || false} scope={{ ...defined, ...imported }}>
<div css={css(badgeStyle)}>Editor</div>
<LiveEditor css={css({ marginBottom: `1rem`, borderRadius: `0.25rem` })} />
<LiveError />
<div css={css(badgeStyle)}>Preview</div>
<LivePreview css={css({ marginBottom: `3rem` })} />
</LiveProvider>
<LazyLiveProvider
code={codeString}
theme={theme}
noInline={noInline || false}
scope={{ ...defined, ...imported }}
/>
)
}
return (
Expand Down
12 changes: 11 additions & 1 deletion examples/status-dashboard/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require(`dotenv`).config({
path: `.env`,
})

const shouldAnalyseBundle = process.env.ANALYSE_BUNDLE

module.exports = {
siteMetadata: {
siteUrl: process.env.SITE_URL || `https://status.lekoarts.de`,
Expand All @@ -28,5 +30,13 @@ module.exports = {
},
`gatsby-plugin-offline`,
`gatsby-plugin-netlify`,
],
shouldAnalyseBundle && {
resolve: `gatsby-plugin-webpack-bundle-analyser-v2`,
options: {
analyzerMode: `static`,
reportFilename: `_bundle.html`,
openAnalyzer: false,
},
},
].filter(Boolean),
}
1 change: 1 addition & 0 deletions examples/status-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"gatsby-plugin-netlify": "^2.1.6",
"gatsby-plugin-offline": "^2.2.7",
"gatsby-plugin-react-helmet": "^3.1.4",
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.10",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-helmet": "^5.2.1"
Expand Down
16 changes: 15 additions & 1 deletion examples/styleguide/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
require(`dotenv`).config({
path: `.env`,
})

const shouldAnalyseBundle = process.env.ANALYSE_BUNDLE

module.exports = {
siteMetadata: {
siteTitle: `Styleguide`,
Expand All @@ -19,5 +25,13 @@ module.exports = {
},
},
`gatsby-plugin-netlify`,
],
shouldAnalyseBundle && {
resolve: `gatsby-plugin-webpack-bundle-analyser-v2`,
options: {
analyzerMode: `static`,
reportFilename: `_bundle.html`,
openAnalyzer: false,
},
},
].filter(Boolean),
}
1 change: 1 addition & 0 deletions examples/styleguide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"gatsby-plugin-netlify": "^2.1.27",
"gatsby-plugin-react-helmet": "^3.1.16",
"gatsby-plugin-theme-ui": "^0.3.0",
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.10",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-helmet": "^5.2.1",
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@
"@testing-library/jest-dom": "^5.11.0",
"@testing-library/react": "^10.4.5",
"@types/chroma-js": "^2.0.0",
"@types/jest": "^25.2.3",
"@types/node": "^12.12.48",
"@types/jest": "^26.0.4",
"@types/loadable__component": "^5.10.0",
"@types/node": "^14.0.20",
"@types/react": "^16.9.41",
"@types/react-dom": "^16.9.8",
"@types/react-helmet": "^5.0.16",
"@types/react-helmet": "^6.0.0",
"@types/styled-system": "^5.1.9",
"@types/testing-library__cypress": "^5.0.6",
"@types/testing-library__jest-dom": "^5.9.1",
"@types/theme-ui": "^0.3.4",
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"@typescript-eslint/eslint-plugin": "^3.6.0",
"@typescript-eslint/parser": "^3.6.0",
"concurrently": "^5.2.0",
"cross-env": "^7.0.2",
"cypress": "^4.10.0",
Expand Down
2 changes: 1 addition & 1 deletion renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
groupName: "types",
packagePatterns: ["^@types"],
packagePatterns: ["^@types/"],
// only upgrade types with approval as they can break transitives
masterIssueApproval: true,
},
Expand Down
1 change: 1 addition & 0 deletions themes/gatsby-theme-minimal-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"@lekoarts/gatsby-theme-minimal-blog-core": "^2.3.10",
"@loadable/component": "^5.13.1",
"@theme-ui/color": "^0.3.1",
"@theme-ui/components": "^0.3.1",
"@theme-ui/presets": "^0.3.0",
Expand Down
Loading

0 comments on commit 667fd33

Please sign in to comment.