Gridsome
Setting up a Gridsome site with Netlify provides a powerful, GraphQL-powered publishing workflow based on Vue.js. This guide covers the complete process from local setup to continuous deployment.
1. Local Gridsome Setup and Project Initialization
Gridsome is a Node.js-based framework and requires Node.js, npm (or yarn/pnpm), and the Gridsome CLI.
1.1. Install Prerequisites and Gridsome CLI
- Install Node.js (LTS version recommended).
- Install the Gridsome CLI globally:
1.2. Create a New Gridsome Site
We'll start with the default starter, which provides a clean structure.
- Create the site: This command clones the default starter, installs dependencies, and initializes a basic Gridsome project.
1.3. Local Test
Run the development server to check the basic setup.
Your site will be running at http://localhost:8080/
. Press Ctrl+C to stop the server.
2. Custom Layouts, Partials, and Static Assets
Gridsome uses a Vue.js component structure where Layouts wrap pages, and Components act as reusable partials.
2.1. Project File/Folder Structure Tree
Your project structure, after customization, will look like this:
my-gridsome-site/
├── node_modules/ # Node.js dependencies
├── dist/ # ⚠️ Generated static site (ignored by Git)
├── src/ # All source code, components, templates, and assets
│ ├── assets/ # Webpacked assets (JS, SCSS, images imported in components)
│ │ └── style.css # Custom CSS imported globally
│ ├── components/ # Reusable Vue components (partials/UI elements)
│ │ ├── Footer.vue
│ │ └── Header.vue
│ ├── layouts/ # The main page wrappers (Layouts)
│ │ └── Default.vue # Primary site shell, defines HTML structure
│ ├── pages/ # Vue components that become site routes
│ │ ├── Index.vue # The site homepage (/)
│ │ └── About.vue # The '/about' page
│ └── templates/ # Templates for programmatically generated content (e.g., blog posts)
├── static/ # Static assets copied directly to the final output (dist/)
│ └── favicon.png
├── gridsome.config.js # Main configuration (plugins, sources, global data)
├── gridsome.server.js # Node.js API to extend GraphQL data, etc.
├── package.json # Node.js dependencies and run scripts
└── .env # Environment variables (ignored by Git)
2.2. Create the Custom Layout
Layouts define the core HTML structure and wrap page content using the <slot />
element.
-
Open the Default Layout:
- File:
src/layouts/Default.vue
- File:
-
Structure the Layout: Ensure it includes the
<Header>
and<Footer>
components.
2.3. Create Components (Partials)
Components are reusable elements stored in the src/components/
folder.
- Create Header Component:
- File:
src/components/Header.vue
- File:
- Create Footer Component:
- File:
src/components/Footer.vue
- File:
2.4. Apply the Layout to Pages
The starter already has an Index.vue
page, which should automatically use the Default.vue
layout.
- Check the Homepage:
- File:
src/pages/Index.vue
- It should contain:
<Layout>...</Layout>
.
- File:
2.5. Manage Static Assets
Gridsome handles assets in two ways:
- Assets (
src/assets/
): For files you want webpacked, minified, and processed (like global CSS or images used in components).- File:
src/assets/style.css
(Add some CSS here).
- File:
- Static (
static/
): For files you want copied directly to the final output root (dist/
). Best forfavicon.ico
,robots.txt
, or large images.- Create the
static
folder at the project root.
- Create the
2.6. Global Asset Import (Optional)
To apply global CSS, import the asset into the layout component.
- Update the Default Layout Script:
- File:
src/layouts/Default.vue
- File:
3. GitHub Setup
3.1. Verify .gitignore
The starter includes a .gitignore
that correctly ignores the built site. Ensure it contains:
3.2. Commit and Push to GitHub
- Initialize Git (if not done by the starter):
- Add all files and commit:
- Create a new repository on GitHub (e.g., named
my-gridsome-site
). - Link your local repo and push: (Replace placeholders)
4. Netlify Setup for Continuous Deployment
4.1. Sign Up and Import Project
- Go to the Netlify website and log in.
- In the Netlify dashboard, click "Add new site" then "Import an existing project".
- Select "GitHub" and choose your repository (
my-gridsome-site
).
4.2. Configure Build Settings
Netlify is optimized for Gridsome and will usually auto-detect the following settings.
Setting | Value (Default for Gridsome) | Note |
---|---|---|
Branch to deploy | main |
The branch Netlify monitors. |
Build command | gridsome build |
The command to generate the static site. |
Publish directory | dist |
The folder Gridsome outputs the static files to. |
4.3. Deploy the Site
Click the "Deploy site" button. Netlify will:
- Fetch your GitHub code.
- Install Node.js dependencies.
- Run the build command (
gridsome build
). - Publish the contents of the
dist
directory.
Your Gridsome site will be live with full continuous deployment.
5. Ongoing Workflow
The Continuous Deployment (CD) pipeline is now established:
- Make changes locally (update components, add new pages).
- Commit your changes:
- Push to GitHub:
- Netlify automatically detects the push, runs the Gridsome build, and deploys the new version live.