<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aashay Trivedi</title>
    <description>The latest articles on DEV Community by Aashay Trivedi (@aashay_trivedi).</description>
    <link>https://dev.to/aashay_trivedi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F164584%2F28691b6a-a7f4-4440-ad39-50af0f8af992.jpg</url>
      <title>DEV Community: Aashay Trivedi</title>
      <link>https://dev.to/aashay_trivedi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aashay_trivedi"/>
    <language>en</language>
    <item>
      <title>How to Perform Pre-rendering in Vue CLI 3?</title>
      <dc:creator>Aashay Trivedi</dc:creator>
      <pubDate>Tue, 08 Oct 2019 16:19:33 +0000</pubDate>
      <link>https://dev.to/aashay_trivedi/how-to-perform-pre-rendering-in-vue-cli-3-4mme</link>
      <guid>https://dev.to/aashay_trivedi/how-to-perform-pre-rendering-in-vue-cli-3-4mme</guid>
      <description>&lt;p&gt;Single page apps are awesome. Developing single-page apps with frameworks like angular, react or vue make your app more user-friendly. Along with that, Internal page navigation is the plus, take Dev.to website for that reason.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;So, everything’s good then What is bad?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;As you know, there is just one HTML file and all the data loads in that file dynamically. Google and Bing claim that they can read the dynamic content but, for the website with several routes it cannot. Also, for single-page apps, google bots need to go an extra step to read dynamic content. The average page loading speed of a single-page app is way higher then the multi-page application having a server.&lt;/p&gt;

&lt;p&gt;I searched on the internet for pre-rendering but could not find a blog for Vue CLI 3 so, I thought I should share my experience. I found prerendering articles for Vue CLI 2 and it took me 2-3 hours to understand for CLI 3. I hope this article will save you time and get the prerendering job done in the least amount of time.&lt;/p&gt;

&lt;h1&gt;
  
  
  How Pre-rending can be helpful?
&lt;/h1&gt;

&lt;p&gt;With pre-rendering, you can create individual HTML files for each route. This helps search engines to read the content on your website and it also helps to improve page loading speed. So, let’s start!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install PreRender SPA plugin&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Install the prerender plugin by typing this command. But the way this plugin created by Vue’s core team member&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="nx"&gt;prerender&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;spa&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;plugin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now, you need to create a vue.config.js file manually at the root of your project. In Vue CLI 2, it comes by default but with Vue CLI 3, it does not. Copy and paste the following code in the vue.config.js file, and include all the routes that you want to prerender.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;PrerenderSpaPlugin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prerender-spa-plugin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="na"&gt;configureWebpack&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;

   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
       &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;PrerenderSpaPlugin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
         &lt;span class="c1"&gt;// Absolute path to compiled SPA&lt;/span&gt;
         &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
         &lt;span class="c1"&gt;// List of routes to prerender&lt;/span&gt;
         &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/about&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
       &lt;span class="p"&gt;),&lt;/span&gt;
     &lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;It’s done. Now run the build. Once the process completes, you will find that inside of the dist folder, individual folders for each route has been created. Each route folder will have an HTML file containing the static data. The Javascript will be stored in an individual folder named JS.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Great, are we done? Well, not yet!
&lt;/h2&gt;

&lt;p&gt;When you deploy the project to the Ubuntu server, you may get an irritating PuppeteerRenderer error and the build will go into an infinite loop. if too many chrome instances are launched then you will get this error and to perform pre-rendering you need to install puppeteer.&lt;/p&gt;

&lt;p&gt;So, install Puppeteer on the Ubuntu server,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="nx"&gt;puppeteer&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the Vue.config.js file, make headless to false. By default, it comes false, but in case you have turned it to true then make it false.&lt;/p&gt;

&lt;p&gt;And finally, you are done. For my website, I have performed prerendering with these steps. I have an improvement in the page loading speed and Google’s ranking after I prerendered. &lt;/p&gt;

&lt;p&gt;If your website is having several dynamic routes then you should choose server-side rendering. It has a server-side framework working. For SSR, whenever your server receives a request for a particular webpage, the code is loaded on the server as well as the client-side. So, you need a powerful server to receive many requests.&lt;/p&gt;

&lt;p&gt;I think I have covered everything regarding pre-rendering. If you find any other error while performing, then please let me know. I will try to help you out.&lt;/p&gt;

</description>
      <category>prerendering</category>
      <category>vue</category>
      <category>vuecli</category>
      <category>spa</category>
    </item>
  </channel>
</rss>
