{"data":{"markdownRemark":{"html":"<p><span style=\"text-align: center; display: block;\">Part of <a href=\"/gatsby-v2\">a series on Gatsby v2</a></span></p>\n<p>You have a site built with Gatsby v1. You want to move to v2. Do you start from scratch and rebuild? Or do you refactor from v1 to v2?</p>\n<blockquote>\n<p><strong>tl;dr</strong> - It depends. In most cases, refactor. You’ll typically be faster refactoring than rebuilding.</p>\n</blockquote>\n<h2>Intro</h2>\n<p>Gatsby v2 has introduced some awesome new stuff. For more on that, read <a href=\"/whats-new-in-gatsby-v2\">What’s new in Gatsby v2</a>. Suffice to say, you’ve decided you want it. At least, if not today, soon. Awesome.</p>\n<p>This raises the question. To rebuild or not to rebuild. Do you start with a clean v2 site and copy from your v1 site? Or would it be smarter to upgrade, and refactor?</p>\n<p>There are a couple of factors to consider here.</p>\n<ul>\n<li>How complicated is your site?</li>\n<li>How many plugins are you using?</li>\n<li>How many separate components do you have?</li>\n</ul>\n<h2>Complexity</h2>\n<p>Do you have any complexity in your site? If you do, where is that complexity? Is your <code class=\"language-text\">gatsby-node.js</code> file super long? Do you have lots and lots of plugins with sophisticated configurations? Are your React components very complex? Lots of data being passed down through many components?</p>\n<p>It's hard to generalise. But we'll try anyway! If you have a lot of complexity in your React components, then you probably want to refactor for v2. The changes introduced will be most noticeable in your <code class=\"language-text\">gatsby-*.js</code> files. This is where most of the significant changes are.</p>\n<p>If your React components are super simple. If the component hierarchy is quite flat. Then, you might want to start fresh on v2. You can hopefully copy much of your source plugin configuration and all of your components into a new v2 starter. Then with a few small tweaks, your site should be migrated.</p>\n<h2>Plugins</h2>\n<p>Do you have a complex setup with many plugins and plugin dependencies in <code class=\"language-text\">gatsby-config.js</code>? If you do, then upgrading to v2 is probably the smart choice.</p>\n<p>One of the biggest changes you'll notice with plugins is dependencies. React and its friends are no longer direct dependencies of <code class=\"language-text\">gatsby</code>. Now you need to install these as well as <code class=\"language-text\">gatsby</code>. The same is true for some plugins.</p>\n<p>When you upgrade Gatsby, you might find that many packages are missing. You can try the following:</p>\n<ul>\n<li>Which plugin is causing the error?</li>\n<li>Check the v2 docs for that plugin</li>\n<li>Does it have <code class=\"language-text\">peerDependencies</code>? These were probably direct dependencies in v1.</li>\n<li>If it does, install them.</li>\n</ul>\n<p>If that doesn't work, you can also try cloning the whole <a href=\"https://github.com/gatsbyjs/gatsby/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Gatsby repo</a>. Then search (grep) the whole codebase for the package that appears in the error. This might point you at where the problem lies.</p>\n<p>If your plugin configuration is very simple, you might be quicker to start with a clean v2 starter. Then add any missing plugins, copy your components, do some renaming](/gatsby-v2-refactoring-cheat-sheet). This will probably bypass any issues of missing packages.</p>\n<h2>Components</h2>\n<p>The changes to components in v2 are fairly simple.</p>\n<ul>\n<li><a href=\"/how-do-layouts-work-in-gatsby-v2\">No more layouts</a></li>\n<li><a href=\"/staticquery-in-gatsby-v2\">The option to use GraphQL everywhere</a></li>\n<li><a href=\"/gatsby-v2-refactoring-cheat-sheet\"><code class=\"language-text\">pathContext</code> renamed to <code class=\"language-text\">pageContext</code></a></li>\n</ul>\n<p>Is your component hierarchy quite simple? Do you have a small number of large components? Then starting with a new v2 Gatsby starter might make sense.</p>\n<p>Otherwise, do you have a lot of separate components? Do you have components with lots of subcomponents? In this case, it's probably easier to upgrade. Moving many components into a new project could be difficult.</p>\n<p>Do you have many \"page\" components? Each one will require some changes. If there are lots of them, upgrading will probably be easier.</p>\n<h2>Upgrade or start over</h2>\n<p>Hopefully this article has given you some insight into the decision. Unfortunately we can't offer a clear prescription that applies to all cases.</p>\n<p>The best overall advice, try it and see. It's easy to go back and try the other option if you use <code class=\"language-text\">git branch</code> at the start.</p>","excerpt":"Part of  a series on Gatsby v2 You have a site built with Gatsby v1. You want to move to v2. Do you start from scratch and rebuild? Or do…","timeToRead":3,"frontmatter":{"date":"July 21, 2018","path":"/should-i-rebuild-my-site-for-gatsby-v2","title":"Should I rebuild my site for Gatsby v2?"}},"relatedPosts":{"edges":[{"node":{"id":"88e68246-cc05-58c4-9cb0-9fa48bc65259","frontmatter":{"title":"Gatsby v2 refactoring cheat sheet","path":"/gatsby-v2-refactoring-cheat-sheet","tags":["v2","cheat sheet"]}}},{"node":{"id":"1aef1790-d364-5a28-ade8-d6196727902c","frontmatter":{"title":"Getting started with Gatsby v2","path":"/getting-started-with-gatsby-v2","tags":["v2"]}}},{"node":{"id":"c8ef7f7d-dffc-5aae-b6a0-0084762b39f0","frontmatter":{"title":"Gatsby v2","path":"/gatsby-v2","tags":["v2","beta"]}}},{"node":{"id":"43eb2d0b-dabd-5c3d-8f96-41eeffd1c003","frontmatter":{"title":"How do layouts work in Gatsby v2","path":"/how-do-layouts-work-in-gatsby-v2","tags":["v2"]}}},{"node":{"id":"36c6d2e1-eff2-5062-aee4-518ccb6f4ea8","frontmatter":{"title":"StaticQuery in Gatsby v2","path":"/staticquery-in-gatsby-v2","tags":["v2"]}}},{"node":{"id":"3a89bcb1-591a-5b78-bb39-6a8488d0ce69","frontmatter":{"title":"What's new in Gatsby v2","path":"/whats-new-in-gatsby-v2","tags":["v2","beta"]}}},{"node":{"id":"9a16f7fc-6fa5-5328-816c-35542c1c38ec","frontmatter":{"title":"When should I upgrade to Gatsby v2?","path":"/when-should-i-upgrade-to-gatsby-v2","tags":["v2"]}}},{"node":{"id":"979a29c5-06ed-5582-b0be-4c37f26b65d4","frontmatter":{"title":"Enable absolute imports for Gatsby v2","path":"/enable-absolute-imports-for-gatsby-v2","tags":["v2"]}}},{"node":{"id":"5eb98a7e-3fd2-5edf-a9f8-44f5e25da39d","frontmatter":{"title":"GatsbyJS source plugin for eventbrite.com","path":"/gatsby-source-eventbrite","tags":["v2","source","eventbrite"]}}},{"node":{"id":"374bf18f-0f86-54c8-bdb1-f051527d8210","frontmatter":{"title":"WordPress starter for GatsbyJS","path":"/gatsby-starter-wordpress","tags":["v2","starter","wordpress"]}}},{"node":{"id":"737d2352-faae-5e91-b298-07399aaf3b1c","frontmatter":{"title":"Starter project for GatsbyJS","path":"/gatsby-central-starter","tags":["v2","starter"]}}}]},"allCommentsJson":null,"allRatingsJson":null},"pageContext":{"tags":["v2"]}}