What is the best way to add scripts in Nuxt 3, for SSG pages? - nuxtjs3

I am porting over an older website into Nuxt 3. This older website has numerous <script> tags referring to local .js files. The intent is to generate pages using Nuxt3's SSG functionality to host the site, so any optimization Nuxt 3 can provide would be the preferred method. What is the best way to include these scripts?
Thank you.

Related

Is there any way to add CMS to Nextjs website (such as Wordpress)?

I developed a website using Nextjs (Client side only, and used Nextjs for the SEO).
I wanted to ask if there is a way to convert this website somehow from Nextjs to Wordpress or anything else, or even somehow connect it to CMS application, so my client can modify images and content any time he want by his own.
Currently, the web application in Nextjs is pretty static, all the pages and conntent are hard coded wroten.
All my data are in JSON files and such are the images in the website.
Yes! This is a pretty hot topic right now, and there are many ways to accomplish it.
Here are the general guidelines:
Set up a "headless CMS" - this can be WordPress (set up in a special way so you are using just the backend) - or there are many other popular options, such as Contentful, Sanity, Prismic...
Your CMS needs to have an API for Next.js to use. If you go with WordPress, you can use the built-in REST API - or you can use the WP GraphQL plugin
This is such a popular topic, that if you search around, you'll find many helpful guides that go into more detail. You'll want to search "Next.JS with WordPress headless CMS"
Here's one example I found that uses GraphQL and looks fairly thorough.
Or, if you're not set on WordPress, check out Next.js-specific information for other popular headless CMS's - most of them will have specific documentation and guides for Next.JS - for example Sanity's Next.JS Guides.
WordPress is solid and flexible - but if you're not already a fairly strong WP developer, then I might recommend going with one of the more pre-packaged options (like Sanity, Prismic, Contentful, etc.) - many of them have a free tier.

Wordpress & Vue & Nuxt - Integration - wp_enqueue_script

I have an existing website where I am gradually replacing the html/css interfaces with Vue technology. So now I have pages with two logics
Pages completely in vue
Pages with html/css parts and vue parts.
Currently I am using Vue (without Nuxt) with success to do this migration. In my wordpress theme I load vue scripts as follows
wp_register_script('vue-app', $directory_uri . '/js/app.js', array(), $version, true);
wp_enqueue_script('vue-app');
In order to improve my project I am switching to Nuxt. But I can't keep the same logic of integration. Nuxt does not create a unique app.js. Nuxt is generating a whole bunch of files and I cannot load them synchronously. Neither in build nor in dev (hot-module-replacement).
I don't know how to keep my logic 1 and 2 with Nuxt. Do you have any solutions ?
If you want to use Nuxt to it's full potential and keep Wordpress, you need to use Wordpress as a headless CMS. Meaning that you may use Full static and generate all of your pages during build time by reaching to your Wordpress app.
I guess that your current Wordpress + Vue flow is lacking SEO hence why you're trying to reach upon Nuxt. But to my knowledge, you will not be able to just plug it like that with your wp_register_script.
Or maybe try to mount it for every one of your routes .../about, .../our-team etc... Not a wordpress expert tho.

Can I add anuglar app to my wordpress site?

So i have built an angular website that uses the GoogleBooksAPI to fetch some book list. And then I show it on my single page app.
Now, i'd like to deploy it somehow to see if it's working.
So i tried to add the project to github pages. github project link:
https://github.com/DrorSC/DrorSC.github.io
And was unsuccesful..
So i thought on a different option. I have a domain, and a wordpress site on it. Maybe i can add the files to my Cpanel and load it into my domain? Or can i do it straight from wordpress?
Tried to look for answers, couldn't find.
Please help. thank you :)
If I understand correctly I think Angular Element will be your best choice. It works the best if you want to integrate Angular web app into your existing website.
Building Custom Elements / Web Components with Angular 6
After build the project. You can use the content of the dist directory into your host.
If you will put your code into a subfolder, you will need specify the path as argument on the CLI for the build.

Mixing Wordpress eCommerce site with external login based Vue Frontend Best Practices

I am new to web development and and would like advice about what is the usual best practices to achieve what I am trying to do.
I am in charge of writing a frontend app using Vue. This frontend will require a login to access the app. The app will be hosted on Amazon.
However we are also wanting to build an eCommerce site in Wordpress or equivalent that sits on the root of the website, (eg www.mywebsite.com) with the app accessible through a "sign in" button. If the user presses the sign in button we want the location bar location to not change from the website they are on (www.mywebsite.com), even though the Wordpress site and Vue frontend may be stored on different locations/domains.
If the site is made in Wordpress, we can get another developer to do that webpage for us, while I work on the frontend. However we want the experience to be relatively seamless between connecting to the wordpress root site, clicking on the sign in button and being taken to the Vue frontend.
Is this possible? Do both sites have to be hosted on the same server for it to work (eg an Amazon EC2 server which hosts two webpages, the wordpress one and the vue one)?
Or can the wordpress put a link to the Vue frontend which doesn't change the web location to the user?
Or (worst case scenario) do we need to make both webpages in Vue as one Vue application, some pages requiring login to access and others not?
Thanks kindly for any assistance.
So in order to use Vue and WordPress together, you can either write 2 separate applications. One for the Frontend and one for the Backend, which is perfectly fine or you can simply write a WordPress Application with a Vue Theme.
This is how this could look like:
WordPress Backend
You can use a normal WordPress backend, where you can build the architecture you want to. In addition, you need to set up the REST-API Wordpress provides. So this also means, just use plugins which support it. Otherwise, you would need to write custom endpoints. For example, Woocommerce would be a good e-commerce plugin, since it supports the API.
Learn more about it here: https://v2.wp-api.org/
Of course, you can host your WordPress installation on Amazon. Here is a good guide for that: https://aws.amazon.com/de/getting-started/tutorials/launch-a-wordpress-website/
Notice: The REST-API is available in core since 4.7. If you are using an older version you would need to install a plugin.
WordPress Frontend
In order to create your Frontend, I'd recommend you to make a custom theme. Since you are just serving static files this can be done pretty easy. But still, you don't need to reinvent the wheel.
There's a really good starter theme out there: https://github.com/EvanAgee/vuejs-wordpress-theme-starter
It comes with all the stuff you need to get started and since it is just a theme, you can simply set up a usual WordPress hosting without handling Domains of multiple applications.
In order to get the data from the Backend, you would simply make calls to the REST-API. Here's an example: https://github.com/EvanAgee/vuejs-wordpress-theme-starter/blob/master/src/api/index.js

Connecting Next.js to Wordpress

I have a fresh WordPress site set up on InMotion. I want to limit WordPress to the backend in terms of storing content and serving it via its API. I want to use Next.JS/React for the front end. My problem is that I am unsure how to connect the two.
Can anyone point me to a tutorial or provide advice on how I can install Next.JS in my site files? Where should Next.JS and its JS files reside? Once installed how can I have my Next.JS javascript files become the theme for my WordPress installation? I have searched the net but there is scant information on these questions. Thanks!
Basically you fetch data from the WordPress API (REST or GraphQL) to your Next.js or other React web application.
I recommend to not mix source code of both things - the React web app would be separate project, it is integrated with WordPress just through the API.
If you google "next.js wordpress" then you would find a few things:
https://github.com/zeit/next.js/search?q=wordpress&type=Issues
a few mentions of WordPress in this issue: https://github.com/zeit/next.js/issues/727
https://react-etc.net/entry/graphql-and-next-js-for-building-wordpress-sites-with-react-js
https://medium.com/#proposalpaul/next-js-3-0-headless-wordpress-in-production-a-deep-review-e9758d29c212

Resources