Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building Real-World Web Applications with Vue.js 3

You're reading from   Building Real-World Web Applications with Vue.js 3 Build a portfolio of Vue.js and TypeScript web applications to advance your career in web development

Arrow left icon
Product type Paperback
Published in Jan 2024
Publisher Packt
ISBN-13 9781837630394
Length 318 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Joran Quinten Joran Quinten
Author Profile Icon Joran Quinten
Joran Quinten
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Part 1: Getting Started with Vue.js Development
2. Chapter 1: Introduction to Vue.js FREE CHAPTER 3. Chapter 2: Creating a Todo List App 4. Chapter 3: Building a Local Weather App 5. Chapter 4: Creating the Marvel Explorer App 6. Part 2: Intermediate Projects
7. Chapter 5: Building a Recipe App with Vuetify 8. Chapter 6: Creating a Fitness Tracker with Data Visualization 9. Chapter 7: Building a Multiplatform Expense Tracker Using Quasar 10. Part 3: Advanced Applications
11. Chapter 8: Building an Interactive Quiz App 12. Chapter 9: Experimental Object Recognition with TensorFlow 13. Part 4: Wrapping Up
14. Chapter 10: Creating a Portfolio with Nuxt.js and Storyblok 15. Index 16. Other Books You May Enjoy

Generating a standalone website

We now have a functional portfolio. This type of website has very static content: it doesn’t change depending on the visitor and will probably not receive daily updates in terms of code! This means that we can optimize the output of what we will deploy to the public.

The portfolio we’ve created is a perfect use case for static site generation. Normally, Nuxt would run as an active process on a server, where it can respond directly to requests and fetch data in real time. A good example is the Quiz server we built in Chapter 8. But since we don’t need real-time data when publishing, we can leverage another capability of Nuxt. When generating a static site, Nuxt runs as an application initially and indexes all of the internal links. For every internal link, it will retrieve the data from the server once and then write the output to a static collection of files.

Let’s see this in action! The command is already part of our package.json scripts, but we need to slightly modify it so that we can pass the API key we need to access the data:

…  "scripts": {
    "build": "nuxt build",
    "dev": "NODE_TLS_REJECT_UNAUTHORIZED=0 nuxt dev --dotenv .env --https --ssl-cert localhost.pem --ssl-key localhost-key.pem",
    "generate": "nuxt generate  --dotenv .env",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
…

We can just run the following command in the terminal:

npm run generate

You will see that the required files for a static site are being generated. On completion, the Nuxt generation process will return a command you can use to test the website as a static site:

npx serve .output/public

Running this command will start a simple HTTP web server. There is no Nuxt process running! This is just the browser running HTML, CSS, and JavaScript files. All of the contents from the CMS are now bundled as part of the website. Well, except for the images – they are served from the Storyblok CDN, which is optimized for doing just that.

We’ll see how we can make our static site public in the next section!

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image