This series of articles will show you how to build a JAMStack e-commerce shop using the latest tech; Nuxt 3 for the front-end, Strapi 4 for the CMS backend, and Snipcart to power the e-commerce.
Here's a link to the shop that we've built, if you follow this series of blog posts this is what you'll also end up with Pick a Sick Wick.
We've done our own designs for this little demo and they can be found here, so as we take you through how to build this out, I will follow a design that we've done for this series.
Watch the video or follow along below.
If you are the kind of person that likes to dive straight into code, we have created example repositories for both the Nuxt and Strapi parts:
I can't tell you how excited we've been, waiting in anticipation for Nuxt 3 and Strapi 4 to come out, and now they're here, and we're ready to get our hands dirty and start using them straight away. I've always wanted to build an online candle shop, so I thought now's the time, and I can show you how to do it too, so let us go and Pick a Sick Wick.
Project setup with Strapi and Nuxt
If you're the sort of person that likes to get straight into the code, then look no further; you can find the repos:
The front-end is using Nuxt 3, and the repo is here
The backend is using Strapi, and the repo can be found here
Feel free to pull it down and dig in.
Here's a step by step guide on how to build your own shop, so let's stop waffling and let's get building.
Just to give you a little heads up, our folder structure is going to look something like this:
Let's just create our folder and go into it, open up your terminal and run:
Strapi 4
Now we're going to get Strapi 4 setup to create the data ready to be pulled through the Nuxt 3 front-end.
Let the terminal do the hard work for you, sit back have a sip of coffee and a biscuit. Once it's finished, a new tab will open in your browser here: http://localhost:1337/admin. You now just need to create your account.
Tada! How easy was that?! Here's your Strapi Dashboard; if you're used to using Strapi 3, you'll see some differences here; if you ask me (and I know you're not, but here's my opinion anyway 🙈), I think it looks a lot cleaner, lighter and nicer.
Let's jump in and start creating the architecture of the products by creating a collection type.
Create the collection type like so:
Then add in the fields you require; for now, we'll add in these fields :
Title - Text field
Description- Text field
Image - Media field
Prices - Number field
Now that you've added in your fields, make sure you save the collection. Your fields should look something like this:
Click the button in the top left and go to Content Manager > Products and, let's add in some new entries; for me, I'm going to be adding in some candles.
Click Add new entry and fill out all the data; once you're done, click Save and Publish and add in a couple more. We have added in some silly joke names because we thought it was funny haha.
Wahoooo, now you should have a list of products 🕯🛍 !!
Now, all we need to do is make the product content public to fetch it from the frontend. To do this go to General > Settings > Users & Permission Plugin > Roles.
Click Public and open out the Product accordion and check to find and findone; finally, just save it, and your products data should now be public.
Wahoooo, now you're backend is all set up and ready to party; let's move on to the frontend and set up Nuxt 3. Open up terminal and type:
Now just head into that directory:
Install all of the dependencies:
If you're anything like us, we use Taliwind on every project, and this one is no different. So let's get that setup:
Generate the Tailwind and Postcss config files
Time to open up your code in your chosen editor; for me, it's VSCode; just do that from the command line, like so:
You will need to add some config to your nuxt.config.ts file, lets also add in the Google fonts whilst we are here. The ones we're using are Playfair Display and Source Sans Pro.
Your code config file should look like this:
Finally, let's get it up and running, one thing to note is your Node version needs to be 14 or higher. So, go to your terminal and type:
Wahoooo!! How easy was that!? Your Nuxt site should now be up and running, if you've nothing else running, it will probably be on port 3000, and the URL will be http://localhost:3000/. Open it up and go check it out. You should have something like this:
To check you've got Tailwind up and running okay, you can head back over to the code base and into the app.vue file and add a Tailwind class around
On the frontend you should see something beautiful like this.
We've done some designs for this project, so I'll be following them whilst going through this tutorial.
Before we go on let's add in some default colours and fonts into tailwind.config.js.
Right, we're making headway now; if you're still with me, thank you, I'm pleased I've not bored you too much so far, hehe, and if you're not, I totally understand.
Time to get the products from Strapi coming out in the front-end. Buckle up this is going to be fun.
In the root folder, create a new directory called pages within that create a page called index.vue. This is going to be the new homepage. We're going to tidy it up and split everything into its own components in the blog post, but for the time being, we just want to try and get the data back from Strapi.
First, we want to fetch all the data, then we want to loop over all the products and put the data out onto the homepage using Nuxt 3, this is really easy to do and the code is fetch the data is only 1 line, sexy if you ask me. useFetch is a global helper function provided by Nuxt 3 that will load the data for the page server side, or during static generation of the page.
<script setup> allows you to use the more streamline syntax to create your Vue components (e.g. you don't have to register components or create data objects).
To get the index page showing we just need to edit our app.vue file to look like this. This is the route file that kicks everything off. Nuxt page is a component that is added by Nuxt and provides a location for your Nuxt pages to appear.
If you check your browser you should have the title and description of your products wooooo 🎉
Wooo! Fingers crossed that's all working for you but if you have any questions feel free to get in touch and ask any more questions via our website or Twitter. There's going to be a few more blog posts in this series, so feel free to subscribe to our newsletter to find when they've been released.
Thank you for reading and next we will be building out the design, and all of the components etc. Once we've got it working we will then integrate Snipcart. And it won't be too long until you can have your own shop.
Creating an internationalised site with Strapi and Nuxt
We were really excited when Strapi released a new update a few weeks ago that included internationalisation! This post will show you the basics of creating an internationalised site using Strapi and Nuxt.
Dynamic social images with Nuxt, Cloud Functions and Cloudinary
Every little helps when trying to get your content noticed on social media, and having an eye-catching sharing image could be the difference between getting someone passing you by or someone clicking through.
This post will guide you by creating dynamic social sharing images unique to each page/post using Firebase cloud functions, Cloudinary and Nuxt.