{"action":"created","issue":{"url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/8917","repository_url":"https://api.github.com/repos/gatsbyjs/gatsby","labels_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/8917/labels{/name}","comments_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/8917/comments","events_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/8917/events","html_url":"https://github.com/gatsbyjs/gatsby/pull/8917","id":367873312,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIxMTgxNjI2","number":8917,"title":"Composing Gatsby Sites","user":{"login":"ChristopherBiscardi","id":551247,"node_id":"MDQ6VXNlcjU1MTI0Nw==","avatar_url":"https://avatars1.githubusercontent.com/u/551247?v=4","gravatar_id":"","url":"https://api.github.com/users/ChristopherBiscardi","html_url":"https://github.com/ChristopherBiscardi","followers_url":"https://api.github.com/users/ChristopherBiscardi/followers","following_url":"https://api.github.com/users/ChristopherBiscardi/following{/other_user}","gists_url":"https://api.github.com/users/ChristopherBiscardi/gists{/gist_id}","starred_url":"https://api.github.com/users/ChristopherBiscardi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChristopherBiscardi/subscriptions","organizations_url":"https://api.github.com/users/ChristopherBiscardi/orgs","repos_url":"https://api.github.com/users/ChristopherBiscardi/repos","events_url":"https://api.github.com/users/ChristopherBiscardi/events{/privacy}","received_events_url":"https://api.github.com/users/ChristopherBiscardi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-10-08T16:51:09Z","updated_at":"2018-10-19T18:29:34Z","closed_at":"2018-10-16T22:36:11Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/8917","html_url":"https://github.com/gatsbyjs/gatsby/pull/8917","diff_url":"https://github.com/gatsbyjs/gatsby/pull/8917.diff","patch_url":"https://github.com/gatsbyjs/gatsby/pull/8917.patch"},"body":"This is the first step towards gatsby themes. It is low level and defines the way multiple gatsby sites compose by defining the way in which gatsby-config's compose. Everything else will build on top of this composition model so it's important to make it extensible and maintainable for the future.\r\n\r\nFor those that are mathematically inclined, this defines a monoid for the gatsby-config data structure such that `(siteA <> siteB) <> siteC === siteA <> (siteB <> siteC)`. This makes it nice when thinking about sub-theming in the future (imagine a complex `ThemeA <> subthemeA <> ThemeB <> subthemeB <> user-site` situation)\r\n\r\nThis method of composition opens the door to themes and sub-themes and allows us to get more user input into how to deal with potentially conflicting artifacts (such as two singleton plugins being defined), test out approaches to generic overriding the rendering of components in user-land, and more.\r\n\r\n## Themes\r\n\r\nA theme is defined as a parameterizable gatsby site. This means that gatsby-config can be a function that accepts configuration from the end user or a subtheme. This is important because in the current state of the world when setting up plugins like `gatsby-source-filesystem`, we need them to be configured with a `__dirname` from the user's site (we could have a special `__inTheCurrentSite` value in the future instead).\r\n\r\nIn the end-user's site, we declare a \"theme\" using the `__experimentalThemes` keyword in gatsby-config. We use this keyword so that people are aware this functionality is experimental and may change without warning. A theme can be configured in the same way plugins are configured (TODO: change `[theme, config]` syntax to match plugin `{resolve:,options}` form) so that the userland APIs match up.\r\n\r\n```js\r\n// gatsby-config.js\r\nmodule.exports = {\r\n  __experimentalThemes: [[`blog-theme`, { dir: __dirname }]],\r\n}\r\n```\r\n\r\nThe theme then includes a gatsby-config.js which allows it to defined all of the expected fields, such as plugins, and also configure them based on user input. (TODO: looks like gatsby-config.js is ignored in the .gitignore file for the theme package in commit #2)\r\n\r\n```js\r\n// blog-theme gatsby-config.js\r\nmodule.exports = ({ dir }) => ({\r\n  siteMetadata: {},\r\n  plugins: [\r\n    `gatsby-mdx`,\r\n    {\r\n      resolve: `gatsby-source-filesystem`,\r\n      options: {\r\n        name: \"blog-posts\",\r\n        path: `${dir}/blog-posts/`,\r\n      },\r\n    },\r\n  ],\r\n})\r\n```\r\n\r\n### Composing themes\r\n\r\nMultiple themes can be used, although there is (intentionally) nothing included in this PR to stop or resolve potential conflicts (for example if a gatsby plugin needs a singleton instance for some reason).\r\n\r\n```js\r\n// gatsby-config.js\r\nmodule.exports = {\r\n  __experimentalThemes: [`blog-theme`, `store-theme`],\r\n}\r\n```\r\n\r\n### Themes as plugins\r\n\r\nThemes are also included in the plugin list, so they can take advantage of using files such as `gatsby-node`. When being used as plugins, themes receive the full themeConfig as the options object. As an example, a blog theme could be instantiated multiple times on a site, once for blog posts and once for product reviews.\r\n\r\n```js\r\n// gatsby-config.js\r\nmodule.exports = {\r\n  __experimentalThemes: [\r\n    [`blog-theme`, { baseUrl: '/posts' }},\r\n    [`blog-theme`, { baseUrl: '/reviews' }]\r\n  ],\r\n}\r\n```\r\n\r\n# etc\r\n\r\n##### Commits\r\n\r\nThis PR contains two commits. The first is the actual functionality, the second is a set of examples (a theme defined as an npm package and an example site using said theme). I expect to remove the second commit before merging, but am open to other approaches to keep an example, etc around and develop it further as we progress.\r\n\r\n##### This PR intentionally does not cover:\r\n\r\n- Defining data types in any way different than the current sourcing patterns\r\n- Any official sub-theming support for overriding components, etc\r\n  * the only way to \"override\" things right now is to use gatsby lifecycles (ex: on-create-page hooks) to replace the full page component.\r\n  * still technically possible in user-land, planned but not included in core yet\r\n"},"comment":{"url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/comments/431456104","html_url":"https://github.com/gatsbyjs/gatsby/pull/8917#issuecomment-431456104","issue_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/8917","id":431456104,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMTQ1NjEwNA==","user":{"login":"ghardin137","id":582811,"node_id":"MDQ6VXNlcjU4MjgxMQ==","avatar_url":"https://avatars0.githubusercontent.com/u/582811?v=4","gravatar_id":"","url":"https://api.github.com/users/ghardin137","html_url":"https://github.com/ghardin137","followers_url":"https://api.github.com/users/ghardin137/followers","following_url":"https://api.github.com/users/ghardin137/following{/other_user}","gists_url":"https://api.github.com/users/ghardin137/gists{/gist_id}","starred_url":"https://api.github.com/users/ghardin137/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghardin137/subscriptions","organizations_url":"https://api.github.com/users/ghardin137/orgs","repos_url":"https://api.github.com/users/ghardin137/repos","events_url":"https://api.github.com/users/ghardin137/events{/privacy}","received_events_url":"https://api.github.com/users/ghardin137/received_events","type":"User","site_admin":false},"created_at":"2018-10-19T18:29:34Z","updated_at":"2018-10-19T18:29:34Z","author_association":"CONTRIBUTOR","body":"I know this has already been merged, but this actually causes problems with the tutorial repo.  gatsby-starter-hello-world does not contain a gatsby-config.js file and this PR isn't checking if the config file exists before trying to use it. "}}
{"actor":{"display_login":"ghardin137"}}