Skip to content
/ sveltekit-wp-bs5 Public template

Experimental, try out SvelteKit with bootstrap5, WordPress, WPGraphQL & more.

License

Notifications You must be signed in to change notification settings

mandrasch/sveltekit-wp-bs5

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

February 2023: See my other experiment as well with WordPress REST API, https://github.com/mandrasch/sveltekit-pico-headless-wp

sveltekit-wp-bs5

Beware: This is not yet SvelteKit 1.0, needs updates/migration. sveltejs/kit#5774

Experimental learning project, connecting a SvelteKit-frontend (made with bootstrap5) to a WordPress backend via WPGraphQL-plugin. This is called a 'headless WordPress'-setup. It's work in progress.

Local Development Setup

Backend (via DDEV)

First time install (see WordPress quickstart):

cd wp-backend/
ddev start && ddev exec wp core download && ddev launch

After installation, setup our child theme and graphql plugins (via WPCLI):

ddev wp theme activate twentytwentytwo-child
ddev wp plugin install --activate wp-graphql atlas-content-modeler
ddev wp plugin install --activate https://carbonfields.net/zip/latest/
ddev wp rewrite structure '/%postname%/'
  • 👷‍♂️ TODO: https://github.com/matepaiva/wp-graphql-crb needs to be installed as well, right now only possible with composer?
  • 👷‍♂️ TODO / decide: Use (classic editor) or use Gutenberg (rich, but complex?)? ddev wp plugin --activate classic-editor
  • 👷‍♂️ TODO / decide: Use atlas-content-modeler (how can we store json for data model in git?) or cpt-ui (types generation can be exported to PHP? ddev wp plugin --activate custom-post-type-ui)

Afterwards you only need to run

ddev start

Frontend (SvelteKit)

cd frontend/
npm install

.env.local already exists, just run

npm run dev

to start local development.

TODO / missing features


Notes (maybe outdated)

Stack / tutorials:

** Frontend **

  • SvelteKit
  • bootstrap5

** Backend / Wordpress: **

Big thanks to

Try it out in Gitpod

Open in Gitpod

Note for Gitpod: You must create .env.local (see .env.local.example) in order to connect a WordPress instance with WPGraphQL-plugin. Use CTRL + c to abort and run npm run dev afterwards again.

Use it locally

See "How can you use this" below.

Technical background

Currently I use @sveltejs/adapter-static, but I also want to test (sustainable) node hosting with @sveltejs/adapter-node on providers like render.com in future.

TODOs

How was this created?

  1. Create (empty) github repo without license/README
  2. Clone it to local harddrive, go to folder:
  3. Run npm init svelte@next in the new repo folder
  4. npm install bootstrap - install bootstrap5
  5. Add preprocess npm install --save-dev svelte-preprocess
  6. npm install --save-dev sass postcss autoprefixer for scss
  7. Add preprocess config for postcss autoprefixer & sass in config svelte.config.js
  8. Run npm i --save-dev @sveltejs/adapter-static@next, add to config, see here: https://github.com/sveltejs/kit/tree/master/packages/adapter-static#usage
  9. Added .vscode/-folder,.github/(action)-folder + gitpod.yml config
  10. Add process.env.PATHS_BASE & dev to config
  11. Add src/route/__layout.svelte for scss and js loading
  12. Add gutenberg standard styles npm install @wordpress/block-library --save, add them them to __layout.svelte thanks to https://www.youtube.com/watch?v=Naz0Fv_VVQk
  13. And most importantly: Add static/.nojekyll otherwise GitHub Pages won't work!! 🤦

Big thanks to

How can you use this?