Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design Concept: Gatsby #4

Open
arcticicestudio opened this issue Aug 22, 2019 · 0 comments
Open

Design Concept: Gatsby #4

arcticicestudio opened this issue Aug 22, 2019 · 0 comments

Comments

@arcticicestudio
Copy link
Owner

arcticicestudio commented Aug 22, 2019

This epic documents the design concept of the static site generator that'll be used to build arctic’s and serves as a plan for the initial launch. It defines the process steps to decide about aspects like the Gatsby core configuration, Gatsby API implementations, required Gatsby plugins, custom configurations for Babel and Webpack and many more.

🚧 This is a living document which means it is work in progress, not completed yet and will be extended!

What is Gatsby?

Gatsby is a blazing fast modern site generator to build secure, modern and blazing fast websites and apps with React. It is fully compliant to JAMstack which is the web development architecture used to built arctic as documented in #3.

  • Gatsby is one of the most popular and state-of-the-art projects of its kind, comes with many unique features builtin into the core while being fully extensible through a advanced plugin API with an large ecosystem.
  • Gatsby generates PWAs (Progressive Web App) with code and data splitting out-of-the-box™ to only load the critical HTML, CSS, data, and JavaScript so the website loads as fast as possible and prefetches resources for other pages once loaded while clicking around the site to make it feel incredibly fast.
  • Gatsby scales to the entire internet by building sites as “static” files which can be deployed easily on dozens of services and fits perfect when used in combination with a continuous deployment concept like e.g. like Netlify (see Design Concept: Hosting & Continuous Deployment #9).
  • Gatsby provides data through a GraphQL API that can be injected into every component and page while the data can be pulled from almost every source: headless CMSs, SaaS services, APIs, databases, the file system…

Gatsby is much more than just a static “site” generator powered by React as explained by the founder and core team members:

It produces static HTML and then rehydrates into a React app.
Think of it as an opinionated CRA with built-in SSR and nice integrations with CMS.
Gatsby is also there to build apps. — Kyle Mathhews, Founder of Gatsby

Gatsby can handle apps with:

  • User authentication? ✅
  • Dynamic data? ✅
  • Asynchronous requests? ✅
  • Ecommerce? ✅
  • Full-blown SaaS? ✅

You can do SO MUCH MORE than static sites with Gatsby. — Jason Lengstorf , Gatsby Core Team Developer

There are countless more features, but it is out of scope for this document to introduce these here. Instead, make sure to check their official project website with the extensive, well-written docs and really intense and beginner-friendly tutorials. It also includes a large overview and comparison of all features, a plugin library and inspiring showcases.
In their blog they publish a lot of great guides, tips & tricks and articles like how Gatsy got so popular that they founded Gatsby Inc. and blog posts about the companies feature plans and values.

Implementation Plan

To build arctic with Gatsby there are several process steps that must be planned and implemented. This section splits it up into categories and theirs tasks that will be documented and tracked within this epic.

Gatsby Themes

On July 3rd 2019, the long-awaited Gatsby Themes API was announced.
This allows to extract logic and components into own packages that can be composed together for reuse in other Gatsby projects or as template/starter for new projects.

arctic will make use of this awesome feature by implementing splitting up into multiple scoped (@arcticicestudio) packages for a simply modularized code base:

  1. @arcticicestudio/gatsby-theme-arctic-core — A Gatsby Theme that provides basic and essential plugins and configurations that can simply be used in other projects or serve as base theme. It'll try to be as generic as possible while still being dynamic configurable.
  2. @arcticicestudio/gatsby-theme-arctic-core — The main Gatsby Theme that'll be more opinionated when it comes to CSS-in-JS libraries and usage of other larger projects/plugins that are not only targeted to basic/essential configurations. It will be the main source for core components and layouts that can be used to extend another Gatsby Theme on.
  3. www — The package of the website itself. It will use and compose both Gatsby Theme packages and adds additional Gatsby plugins and configurations specific to the site as well as plugins that can only be applied in this package due to their required loading order (e.g. gatsby-plugin-offline).

Since arctic’s repository structure is a monorepo, the modular architecture comes with even more improvements like hoisted dependencies and a way smoother developer experience due to direct loading of local packages.

Core Configuration

The core configuration of Gatsby is the gatsby-config.js file that will be placed in the root directories of the theme and website packages. It defines project-wide site metadata that can be used through the GraphQL API and configures all plugins that will be used.

All implementation details and requirements are documented and tracked in the corresponding issues:

API Implementations

Gatsby can be customized and extended to the core by providing…

  • …the Node API that gives plugins and site builders many APIs for controlling the build process. It can be implemented in the gatsby-config.js file placed in the project root.
  • …the SSR API to hook into the server-side rendering process. It can be implemented in the gatsby-ssr.js file placed in the project root.
  • … the Browser API to hook into the APIs used for browser related functionality. It can be implemented in the gatsby-browser.js file placed in the project root.

All APIs come with a collection of functions called “Actions” that can be used to manipulate the build.

For more details make sure to read the API specification and philosophy and references for the GraphQL API.

All implementation details and requirements are documented and tracked in the corresponding issues:

Gatsby Plugins

Gatsby is designed to be easily extensible while being functional out-of-the-box™. This is possible by using the powerful plugin API to simply create own plugins or browse the plugin library since there is already a large ecosystem and a plugin for almost everything.

arctic will make use of various plugins to implement features and simplify the code base for a better developer experience.

All implementation details and requirements are documented and tracked in the corresponding issues:

Babel Configuration Modification

Gatsby comes with an already optimized Babel configuration to create SSR “static” websites and apps, but there are also use cases that require to modify and extend this configuration to e.g. add a new Babel plugin for the latest syntax feature/proposal support.
Of course Gatsby provides a way through the Node API by implementing the onCreateBabelConfig function.

All implementation details and requirements are documented and tracked in the corresponding issues:

Webpack Configuration Modification

This is almost the same like the section above about how to modify and extend the Babel configuration but now for Webpack instead of Babel. This can be necessary to e.g. add a builtin or third-party plugin or to add resolve aliases. For sure Gatsby supports this too by providing the onCreateWebpackConfig function through the Node API.

All implementation details and requirements are documented and tracked in the corresponding issues:

@arcticicestudio arcticicestudio mentioned this issue Aug 24, 2019
2 tasks
arcticicestudio added a commit that referenced this issue Aug 24, 2019
Configured TypeScript (1), the typed superset of JavaScript that
compiles to plain JavaScript.
This is the main language on which "arctic" will be built.
Like documented in the "Gatsby" design concept (2), it will be used in
combination with "Gatsby" later on with the
`gatsby-plugin-typescript` (3) plugin.

Note that TypeScript is only used as `linter/validator` and not as
compiler!
The actual compiler is Babel (4) that is configured and used through
"Gatsby".

>>> Configuration

The root project provides the main `tsconfig` for all packages and the
website itself.

>>> Package script

To allow to run the TypeScript linting separately a `lint:ts` package
script has been added that'll also be run through the main `lint` script
flow.

References:
  (1) https://www.typescriptlang.org
  (2) #4
  (3) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-typescript
  (4) https://babeljs.io

Associated epic(s): GH-4
Resolves GH-29
This was referenced Aug 31, 2019
arcticicestudio added a commit that referenced this issue Aug 31, 2019
Initially implemented the Gatsby theme and main website package
configurations (1). The `gatsby-config.js` files of each "Gatsby Theme"
define project-wide site metadata that can be used through the GraphQL
API and configures all plugins that will be used.

>> Site Metadata

All metadata, like defined in GH-6, aew placed in the corresponding
folders for configurations (`src/config`) and data (`src/data`).
Initially this includes information stored in the `package.json` file of
the project. There are also constants for important project root folders
to be used in imports later on like route mappings.

>> Gatsby Plugins

This initial implementations includes the following basic plugins (2)
and packages, split up into the corresponding Gatsby theme packages.

1. `@arcticicestudio/gatsby-theme-core`
   - gatsby-plugin-canonical-urls (3)
   - gatsby-plugin-catch-links][gh-gp-catl]
   - gatsby-plugin-no-sourcemaps (4)
   - gatsby-plugin-react-helmet (5)
   - gatsby-plugin-remove-trailing-slashes (6)
   - gatsby-plugin-robots-txt (7)
   - gatsby-plugin-sharp (8)
   - gatsby-plugin-sitemap (9)
   - gatsby-plugin-typescript (10)
   - gatsby-plugin-webpack-size (11)
   - gatsby-source-filesystem (12)
   - gatsby-transformer-hjson (13)
   - gatsby-transformer-json  (14)
   - gatsby-transformer-sharp (15)
   - gatsby-transformer-yaml (16)
2. `@arcticicestudio/gatsby-theme-arctic`
   - gatsby-plugin-svgr (17)
   - gatsby-plugin-styled-components (18)
   - gatsby-image (19)
3. `www`
   - gatsby-plugin-offline (20)
   - gatsby-plugin-netlify (21)
   - gatsby-plugin-manifest (22)

>> Package Scripts

To provide a simple development flow, new package scripts have been
created to start the Gatsby's development mode and build a production
bundle. This also includes basic scripts like a clean up to remove
possible cache problems and previously created bundles and the currently
not available "collected" scripts to run all scripts of the same
type/task. The npm-run-all (23) package are used to simplify the scripts
and prevent unnecessary long chained commands and OS related problems.

> Babel

Gatsby comes with an already optimized Babel (24) configuration to
create SSR "static" websites and apps, but there are also use cases that
require to modify and extend this configuration to e.g. add a new Babel
plugin for the latest syntax feature/proposal (25) support.
Of course Gatsby provides a way through the Node API (26) by
implementing the `onCreateBabelConfig` (27) function.

"arctic" makes use of the following proposals and plugins:

- "ES Class Fields & Static Properties" (28) through
  `@babel/plugin-proposal-class-properties` (29) (NOTE: This plugin is
  configured with the enabled `loose` option!)
- "ECMAScript Proposal: export default from" (30) through
  `@babel/plugin-proposal-export-default-from` (31)
- `babel-plugin-react-remove-properties` (32) to remove props from React
  elements like `data-testid` attributes added for simplified querying
  in automated tests.

The plugins and Babel options are implemented using Gatsby's provided
actions (33) `setBabelPlugin` and `setBabelOptions`.

> Webpack

This is almost the same like the modified Babel configuration documented
above, but for the Webpack (34) configuration instead. It is used to

- configure the plugin `webpack-bundle-analyzer` (35) to generate a
  "static" report with a JSON stats file stored in a newly created
  `build` directory within the project root.
- configure the plugin `git-revision-webpack-plugin` (36)
- configure the plugin `webpack.DefinePlugin` (37)
- configure "resolve aliases" (38)] (see GH-6 for details about the
  structure concept)
  - `~assets` > `src/assets`
  - `~atoms` > `src/atoms`
  - `~config` > `src/config`
  - `~containers` > `src/containers`
  - `~data` > `src/data`
  - `~hooks` > `src/hooks`
  - `~hooks` > `src/layouts`
  - `~molecules` > `src/molecules`
  - `~organisms` > `src/organisms`
  - `~pages` > `src/pages`
  - `~stores` > `src/stores`
  - `~styles` > `src/styles`
  - `~templates` > `src/templates`
  - `~utils` > `src/utils`

Gatsby also supports this by providing the `onCreateWebpackConfig` (39)
function through the Node API (26).

> TypeScript

In order to make the Webpack "alias imports" with TypeScript,
the module resolution (40) has been configured to make the alias names
and paths available to the compiler.

> React

Since Gatsby v2, React (41) is a peer dependency which allows users to
freely choose the version they'd like to use. "arctic" is initially
build with the currently latest stable version 16.9.0 (42).

References:
  (1) https://gatsbyjs.org/docs/gatsby-config
  (2) https://gatsbyjs.org/plugins
  (3) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-canonical-urls
  (4) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-no-sourcemaps
  (5) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-react-helmet
  (6) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-remove-trailing-slashes
  (7) https://github.com/mdreizin/gatsby-plugin-robots-txt
  (8) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sharp
  (9) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sitemap
  (10) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-typescript
  (11) https://github.com/axe312ger/gatsby-plugin-webpack-size
  (12) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-filesystem
  (13) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-hjson
  (14) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-json
  (15) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-sharp
  (16) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-yaml
  (17) https://github.com/zabute/gatsby-plugin-svgr
  (18) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-styled-components
  (19) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-image
  (20) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-offline
  (21) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-netlify
  (22) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-manifest
  (23) https://github.com/mysticatea/npm-run-all
  (24) https://babeljs.io
  (25) https://babeljs.io/docs/en/plugins
  (26) https://www.gatsbyjs.org/docs/node-apis
  (27) https://www.gatsbyjs.org/docs/node-apis/#onCreateBabelConfig
  (28) https://github.com/tc39/proposal-class-fields
  (29) https://babeljs.io/docs/en/babel-plugin-proposal-class-properties
  (30) https://github.com/tc39/proposal-export-default-from
  (31) https://babeljs.io/docs/en/babel-plugin-proposal-export-default-from
  (32) https://github.com/oliviertassinari/babel-plugin-react-remove-properties
  (33) https://www.gatsbyjs.org/docs/actions
  (34) https://webpack.js.org
  (35) https://github.com/webpack-contrib/webpack-bundle-analyzer
  (36) https://github.com/pirelenito/git-revision-webpack-plugin
  (37) https://webpack.js.org/plugins/define-plugin
  (38) https://webpack.js.org/configuration/resolve#resolve-alias
  (39) https://www.gatsbyjs.org/docs/node-apis#onCreateWebpackConfig
  (40)https://www.typescriptlang.org/docs/handbook/module-resolution.html
  (41) https://reactjs.org
  (42) https://reactjs.org/blog/2019/08/08/react-v16.9.0.html

Epics: GH-4 GH-6
Resolves GH-35
YooCoder17 added a commit to YooCoder17/ice_starter that referenced this issue Oct 20, 2023
Configured TypeScript (1), the typed superset of JavaScript that
compiles to plain JavaScript.
This is the main language on which "arctic" will be built.
Like documented in the "Gatsby" design concept (2), it will be used in
combination with "Gatsby" later on with the
`gatsby-plugin-typescript` (3) plugin.

Note that TypeScript is only used as `linter/validator` and not as
compiler!
The actual compiler is Babel (4) that is configured and used through
"Gatsby".

>>> Configuration

The root project provides the main `tsconfig` for all packages and the
website itself.

>>> Package script

To allow to run the TypeScript linting separately a `lint:ts` package
script has been added that'll also be run through the main `lint` script
flow.

References:
  (1) https://www.typescriptlang.org
  (2) arcticicestudio/arctic#4
  (3) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-typescript
  (4) https://babeljs.io

Associated epic(s): GH-4
Resolves GH-29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants