A boilerplate setup of Nuxt with content from headless Wordpress using the Wordpress GraphQL plugin.
Content Rendering: Nuxt.js (Server-side Vue.js) Content Management: Wordpress Content Retrieval: WPGraphQL GraphQL for Wordpress
- Download and install Docker Desktop.
- Clone the repository:
git clone https://github.com/2wav/wpgql-nuxt-boilerplate.git
. - Change to wp directory:
cd wpgql-nuxt-boilerplate/wp
. - Start the Docker container
docker-compose up
. - Open a web browser and visit localhost:8080.
- Follow the Wordpress installation instructions.
- Go to the plugins page.
- Activate all plugins.
- Go to Settings->Permalinks and set to anything but the default.
- Go to Tools->Import, click Run Importer, and import
WP Import.xml
from thesupport
directory. - Open a new terminal session (leave your Docker session running).
cd
into the/nuxt
directory (if you didn't change directories,cd ../nuxt
).- Install node modules
npm i
. - Start the application
npm run dev
.
- Menu support: See
SiteNav.vue
. You must know the name of your menu.- Menu items also get highlighted when you're on their route!
- Programmatically generated introspection fragment matcher: see
package.json
,/apollo/client-configs/default.js
andfragments.js
. - Get page or post content: see
/pages/_.vue
and/posts/_.vue
. - Get and paginate a list of pages or posts: see
PostDirectory.vue
. - Globally accessible SCSS variables, mixins, and functions: see
/assets/scss
. - Testing with Jest.
- JSDoc working within Vue files.
- @nuxtjs/apollo: Apollo inside Nuxt.
- nuxt-vuex-router-sync: Keep the current route in the Vuex store.
- @nuxtjs/style-resources: Share style resources across components (the
styleResources
block innuxt.config.js
). - @nuxtjs/redirect-module: Easy redirects in Nuxt. Used to make
/wp-admin
link to the wordpress app (see the@nuxtjs/redirect-module
in themodules
section ofnuxt.config.js
). - webpack, node-sass, and sass-loader: Compile SCSS into CSS .
- lodash: Trying to get undefined properties in your queries will tank your whole site, so you'll be using
_.get()
a lot. - jsdoc, jsdoc-vue, jsdoc-export-default-interop, vue-template-compiler: Generate JSDocs from comments, even in Vue templates.
- WPGraphQL: Allow GraphQL queries against the Wordpress database.
- WP Headless: Disable the WP frontend, to avoid confusion.
- We've left the prettier and eslint configurations almost entirely untouched, but with some exceptions.
- We use double quotes in house.
- We also use semicolons.
- We've disabled no-html because that's how we import content from Wordpress.
- We've disabled no-console because you are going to be using it a lot while you're debugging server-side stuff.
- We've imported a few polyfills (fetch, object.assign, and object.entries) from polyfill.io that we frequently need.
- You often need to restart Nuxt after editing nuxt.config.js—do so by typing rs into the terminal session that's running the app.
- You also often need to restart Nuxt from the console if it's crashing on a GraphQL query.
- There are multiple ways to create an Apollo object. We've included examples of writing as an object with properies (/pages/_.vue) and writing as a function that returns an object (SiteNav.vue).
- You have to use the function version if you want to use component data in the query (e.g. in the variables).
- There's currently some odd gql error spew in the console. I'm trying to track it down.