Getting Started with Gridsome

Getting Started with Gridsome

Gridsome is a Vue.js-powered, modern site generator for building the fastest possible websites for any Headless CMS, APIs or Markdown-files

The era of Static Site Generators is changing over time, a lot of cool tools are being created to help foster the JAMStack evolution and developers are embracing these tools. One of the tools for creating blazing fast websites is Gridsome.


Table of Contents

In this article, we’ll be taking a look at how to use Gridsome to create a sample profile listing site, its major features and how it compares to other Static Sites Generators.


What is a Static Site Generator?

Remember how we used to play around with plain HTML sites with a little drop of CSS here and there I used to do that a lot when I started learning. You will naturally call that site we end up building a static site right because there’s no form of dynamic action going on. This is a true fact but it spans over having a static HTML page rendered. Static Site Generators are a new, hybrid approach to web development that allows you to build a powerful, website locally on your computer but pre-builds the site into static files for deployment.


What is Gridsome?

Gridsome is a Vue-powered static site generator for building blazing fast static websites. It is data-driven meaning it uses a GraphQL layer to get data from different sources in order to dynamically generate pages from it. Gridsome is the Vue alternative to Gatsby for React.js.


Features of Gridsome

Gridsome ships with a lot of great features that makes building a static site with Gridsome a great choice. Some of the features it offers includes:

  • Hot-reloading development - See changes in real-time while developing.
  • Vue.js for front-end - Ultra lightweight and approachable front-end framework.
  • GraphQL data layer - Centralized data management for all your data.
  • Automatic page routing - Quickly create and manage pages with files.
  • Progressive image support - Auto resize, optimize & lazy load images.
  • Auto page prefetching - Pages are loaded in the background for fast browsing.
  • Auto optimized code - Get code-splitting and asset optimization out-of-the-box.
  • Fast static page generating - Deploy securely and fast to any Static Web Host.
  • Data source plugins - Add data from popular Headless CMSs, APIs or Markdown-files.
How Gridsome Works?

Gridsome is a website framework that enables us to create fast blazing static sites and how it works is it fetches data from data sources like CMSs, local files or external APIs and store the data in a local database. GraphQL acts as a centralized data management system that manages the data and gives you the ability to extract and use data within your vue components. For development, Gridsome provides a command gridsome develop that starts the local server with hot-reloading and a GraphQL data layer. And for production, the gridsome build command prepares the site for production by bundling and generating HTML files that can be hosted and deployed to any global CDN or FTP.


Comparison with Other Static Site Generators

Along with Gridsome, there are other Static Site Generators available to create your website. I’ll compare Gridsome alongside some other Static Site Generator like Gatsby, Nuxt, Vuepress.


Building a Gridsome SitePrerequisite

In order to follow this tutorial, You’ll need to have the following setup:

  • Node v8.0 or higher
  • NPM (this comes packaged with Node) or Yarn.
  • Basic knowledge of JavaScript and Vue
Installing Gridsome

The first thing we’ll do is to check that Node and npm is installed.

node --version && npm -v

Then, you can install Gridsome CLI by running the following command:

yarn global add @gridsome/cli
// or
npm install --global @gridsome/cli

Next step is to create a new project using the CLI we just installed:

gridsome create gridsome-site

Once that is done installing we can run the Gridsome site with this command:

 cd gridsome-site && gridsome develop

Viola! There you have it, your gridsome site is up and running on port 8080. Gridsome also provides a GraphQL playground environment for testing out queries. And you’ll find it running at http://localhost:8080/___explore.


Folder Structure

We’ll be exploring the folder structure of a gridsome site. In order to fully grasp what Gridsome can do we need to fully understand what each file within the project is specifically used for.

.
├── package.json
├── gridsome.config.js
├── gridsome.server.js
├── static/
└── src/
    ├── main.js
    ├── layouts/
    │   └── Default.vue
    ├── pages/
    │   ├── Index.vue
    │   └── Blog.vue
    └── templates/
        └── BlogPost.vue

Gridsome starter comes fully baked with all the files we need for developing a site, we can see there are already a couple of files in the project directory.

  • package.json - This is where all the dependencies for the project will be stored.
  • gridsome.config.js - This file serves as a configuration file for the gridsome site where you configure plugins.
  • gridsome.server.js: This file is optional and is used to hook into various parts of the Gridsome server.
  • /src directory: This folder is where most of the code lives, we have:
  • main.js - This file contains the application configuration such that it plugs in other parts of the app into the gridsome API.
  • Layouts/ - Layout components are used to wrap pages and templates. The layout component is located in the src/layouts folder and should be indicated as the global component. It also requires a slot component which inserts the content of pages and template components into the layout.
  • Pages/ - The pages are individual components, every component in the pages directory becomes a page on the website. Each page will get its path based on the .vue file location. i.e src/pages/Index.vue will become the homepage and src/pages/about will be rendered as the about page.
  • Templates/ - Templates are used for single post views to GraphQL collections. To add a template create .vue file with the same name as a GraphQL collection to src/templates.
  • /static directory: This directory can be used to store files that will be copied directly to the dist/ folder after the build for example /static/robot.txt.Plugins

With Plugins enabled you can have additional functionalities tied to your Gridsome App. Plugins options are added to gridsome.config.js. In this tutorial, we’ll be building a profile listing site and we will need the gridsome/source-faker plugin to help populate data to the site. Let’s go ahead and set that up.


Plugins

With Plugins enabled you can have additional functionalities tied to your Gridsome App. Plugins options are added to gridsome.config.js. In this tutorial, we’ll be building a profile listing site and we will need the gridsome/source-faker plugin to help populate data to the site. Let’s go ahead and set that up.

Install the plugin using the command:

yarn add @gridsome/source-faker 
or 
npm install @gridsome/source-faker

And add the following to the gridsome.config.js file.

module.exports = {
  siteName: 'Fancy Random Profile',
  siteUrl: '',
  siteDescription: 'A directory listing of random profiles',
  plugins: [
    {
      use: '@gridsome/source-faker',
      options: {
        numNode: 50
      }
    }
  ]
}
Querying data with GraphQL

With Gridsome there are several ways of getting data into your site. Gridsome makes use of GraphQL for data management. Now that we have setup the plugin let’s check out the GraphQL playground and the queries we have access to. Run yarn develop and navigate to http://localhost:8080/___explore

There’s a documentation of all queries and we can see the faker and allFaker queries has been added as a result of the gridsome/source-faker plugin we installed. This data will be used to populate the site we’re building. Now let’s create the profile page.


Displaying the Layout Component

The site we’ll be building will require us to create two pages. First one will be a page with a list of all profiles and the other page which will be the About page will contain details about the site. With Gridsome we have the layouts which are used to wrap pages components. So let’s create a layout called Default.vue and add the following code into it.

<template>
  <div class="container">
    <header class="header">
      <g-link class="title is-size-3" :to="{ name: 'home'}">{{ $static.metaData.siteName }}</g-link>
      <g-link class="subtitle is-size-3" :to="{ name: 'about' }">About</g-link>
    </header>
    <slot/>
  </div>
</template>

You can query data from GraphQL in a Layout component using the static-query like this:

<static-query>
query {
  metaData {
    siteName
  }
}
</static-query>

In the Default.vue file we can see the static-query what this does is it enable you plugin in data from GraphQL into your layout component. Now we are fetching the sitename from Metadata query and using it within the template $static.metaData.siteName. Also by passing in <slot /> we are displaying content of the pages component.


Displaying the Pages Component

Now in order to create the page for displaying random profile, we’ll create an Index.vue file within the pages directory. By default the Index.vue become the homepage in this case, we’ll also create an About.vue component.

<template>
  <Layout>
    <div class="content">
      <div class="card" v-for="edge in $page.allFaker.edges" :key="edge.node.id">
        <div class="card-content columns">
        <div class="column is-2">
          <figure class="image is-128x128">
            <img class="is-rounded" :src="edge.node.avatar.src">
          </figure>
        </div>
        <div class="column">
          <p class="title"> {{ edge.node.author }}</p>
          <p class="subtitle"> <i class="has-text-dark">Contact Email:</i> {{ edge.node.email.src }}</p>
          <p class="subtitle"> <i class="has-text-dark"> Profile: </i> {{ edge.node.title }}</p>
        </div>
        </div>
      </div>
    </div>
  </Layout>
</template>

The page-query is also used for querying data from GraphQL and still does the same thing as static-query only difference is, it is used specifically for Pages and Templates.

<page-query>
query allFaker {
  allFaker (perPage: 10) {
    edges {
      node {
        email,
        author,
        avatar,
        title,
      }
    }
  }
}
</page-query>

And for the About Page, we are not really querying any data from GraphQL all we just have is a text describing what the site is all about.

<template>
  <Layout class="content">
    <p class="title is-4">
      Fancy Random Profile is a website listing random people's profile and details.
    </p>
   <a href="https://github.com/lauragift21/scotch-gridsome">GitHub Repo Available here</a>
  </Layout>
</template>
<script>

Great! We have just completed the profile listing site and here’s what it looks like. You can run yarn develop to start the server.


Deployment

Deploying a gridsome site is usually not a difficult task as tools like Netlify, Zeit Now, GitHub Pages etc are readily available to help out. We’ll be using Netlify to deploy the app we built in this tutorial. To deploy your Gridsome site to Netlify, head over to the Netlify platform and create a new site page, select your project repo from GitHub, GitLab, or Bitbucket and add the following build configuration.

After adding that, click the deploy site button and that should run a build and generate a link to your site. You can check out the profile lisitng site here.


Wrapping Up

In this tutorial, You’ve learned what Gridsome is all about and how to build a static site using Gridsome and also you learned to use its awesome GraphQL layer to query data. Let this not be the end you can explore more by checking out the JAMStack and possibilities of integrating other API to your site using the JAMStack concept.

Learn More

Build a Basic CRUD App with Laravel and Vue

Build a Simple CRUD App with Spring Boot and Vue.js

Full Stack Developers: Everything You Need to Know

ES5 to ESNext — here’s every feature added to JavaScript since 2015

5 Javascript (ES6+) features that you should be using in 2019

24 JavaScript Libraries for Creating Beautiful Charts

12 Concepts That Will Level Up Your JavaScript Skills

Originally published by Egwuenu Gift at https://scotch.io

Top Vue.js Developers in USA

Top Vue.js Developers in USA

Vue.js is an extensively popular JavaScript framework with which you can create powerful as well as interactive interfaces. Vue.js is the best framework when it comes to building a single web and mobile apps.

We, at HireFullStackDeveloperIndia, implement the right strategic approach to offer a wide variety through customized Vue.js development services to suit your requirements at most competitive prices.

Vue.js is an open-source JavaScript framework that is incredibly progressive and adoptive and majorly used to build a breathtaking user interface. Vue.js is efficient to create advanced web page applications.

Vue.js gets its strength from the flexible JavaScript library to build an enthralling user interface. As the core of Vue.js is concentrated which provides a variety of interactive components for the web and gives real-time implementation. It gives freedom to developers by giving fluidity and eases the integration process with existing projects and other libraries that enables to structure of a highly customizable application.

Vue.js is a scalable framework with a robust in-build stack that can extend itself to operate apps of any proportion. Moreover, vue.js is the best framework to seamlessly create astonishing single-page applications.

Our Vue.js developers have gained tremendous expertise by delivering services to clients worldwide over multiple industries in the area of front-end development. Our adept developers are experts in Vue development and can provide the best value-added user interfaces and web apps.

We assure our clients to have a prime user interface that reaches end-users and target the audience with the exceptional user experience across a variety of devices and platforms. Our expert team of developers serves your business to move ahead on the path of success, where your enterprise can have an advantage over others.

Here are some key benefits that you can avail when you decide to hire vue.js developers in USA from HireFullStackDeveloperIndia:

  • A team of Vue.js developers of your choice
  • 100% guaranteed client satisfaction
  • Integrity and Transparency
  • Free no-obligation quote
  • Portal development solutions
  • Interactive Dashboards over a wide array of devices
  • Vue.js music and video streaming apps
  • Flexible engagement model
  • A free project manager with your team
  • 24*7 communication with your preferred means

If you are looking to hire React Native developers in USA, then choosing HireFullStackDeveloperIndia would be the best as we offer some of the best talents when it comes to Vue.js.

Hire React Js Developer from Expert React JS Development Company

Hire React Js Developer from Expert React JS Development Company

Are you looking to [hire React JS developer](https://www.mobiwebtech.com/react-js-development-company/ "hire React JS developer") from a prestigious and reliable React JS development company? Visit at Mobiweb Technologies here we have a big team...

Are you looking to hire React JS developer from a prestigious and reliable React JS development company? Visit at Mobiweb Technologies here we have a big team of expert React JS developers, you can hire them on an hourly, weekly or monthly basis for the successful completion of your dream project.

Top Web Application Developer

Top Web Application Developer

You can also contact a web application development company for your business but then why not to contact the best web application development company that can turn up your business and customer satisfaction ratio to sky touching heights.

Not long-ago internet came into existence and the world has never been the same ever since. The Internet made sure that people and business do evolve at a faster rate than ever and was never merciful to the slow ones. Because of this competition and availability of any business with few clicks made India one of the hubs as IT center. This trend of constantly updating has given rise to smartphones, smart machines, wearable gadgets and a lot more is yet to come in the upcoming years. In such time it is always a good idea to hire Web App Developer from India at your service. They are expert in developing not only websites but web applications as well.

We at HireFullStackDeveloperIndia, have a huge team of experienced developers that have grasped over different domains in front and back end development. You can hire web app developers in India from us with many advantages that you won’t get anywhere else in the industry.

Here is why we are the best option if you are looking forward to hiring web app developers in India:

  • Flexible hiring models available, as per your convenience and requirement
  • Maximum ROI, compared to any other company or team of developers.
  • We provide you with Source code Authorization meaning code written for you belong only to you. It cannot be used or copied anywhere else.
  • All of our developers are sound with agile development methodology, so you will be in a constant loop of suggestions, ideas, trends, and updates about your project.
  • Our developers are good with creating custom web applications as well; it guarantees you a better product without any compromise of non-existing functionalities.
  • You can save huge costing on infrastructure by utilizing our hire web app developer in India program.
  • Your hired developer or team will be easily accessible to your preferred mode of communication.
  • You get to exercise complete control over your team or individual that you hire.
  • We believe in Integrity and Transparency.
  • Our developers are highly creative and motivated to deliver excellence.


HireFullStackDeveloperIndia is a Web Application Development Company in India that is known worldwide for our Innovative guaranteed solutions. You can inquire with us about your project and we will be providing you multiple suitable developers that are the best fit for your requirements. You can evaluate them and select one or multiple whosoever deems fit to you. After this, all you have to do is provide your valuable input to the resource through sprint base project development until you get delivery of your project.

Our engagement model will also allow you to get our development team to your site location and proceed with development from your premises.