Top Related Projects
The React Framework
The best React-based framework with performance, scalability and security built in.
The library for web and native user interfaces.
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
web development for the rest of us
The Intuitive Vue Framework.
Quick Overview
Faust.js is a framework for building headless WordPress sites using Next.js and TypeScript. It provides a set of tools and APIs to seamlessly integrate WordPress content into Next.js applications, enabling developers to create fast, modern, and scalable websites while leveraging WordPress as a content management system.
Pros
- Combines the power of WordPress CMS with the performance and flexibility of Next.js
- Strong TypeScript support for improved developer experience and code quality
- Automatic generation of TypeScript types based on WordPress schema
- Simplified data fetching and state management through custom hooks
Cons
- Steep learning curve for developers not familiar with both WordPress and Next.js
- Limited documentation and community support compared to more established frameworks
- Potential performance overhead due to the additional layer between WordPress and Next.js
- May require additional configuration and setup compared to traditional WordPress themes
Code Examples
- Fetching posts using the
usePost
hook:
import { usePost } from '@faustjs/next';
function SinglePost({ id }) {
const { post } = usePost({
id,
});
if (!post) {
return <div>Loading...</div>;
}
return (
<div>
<h1>{post.title()}</h1>
<div dangerouslySetInnerHTML={{ __html: post.content() }} />
</div>
);
}
- Using the
usePosts
hook to display a list of posts:
import { usePosts } from '@faustjs/next';
function PostList() {
const { posts, hasNextPage, fetchNextPage } = usePosts({
first: 10,
});
return (
<div>
{posts.map((post) => (
<div key={post.id}>
<h2>{post.title()}</h2>
<p>{post.excerpt()}</p>
</div>
))}
{hasNextPage && (
<button onClick={() => fetchNextPage()}>Load More</button>
)}
</div>
);
}
- Querying custom post types using the
client.query
method:
import { client } from 'client';
async function getCustomPosts() {
const { customPosts } = await client.query({
customPosts: {
nodes: {
id: true,
title: true,
customField: true,
},
},
});
return customPosts.nodes;
}
Getting Started
-
Install the Faust.js CLI:
npm install -g @faustjs/cli
-
Create a new Faust.js project:
faust create my-faustjs-app cd my-faustjs-app
-
Configure your WordPress URL in
faust.config.js
:module.exports = { wordpress: { url: 'https://your-wordpress-site.com', }, };
-
Start the development server:
npm run dev
Your Faust.js app is now running and connected to your WordPress site. You can start building your headless WordPress application using Next.js and TypeScript.
Competitor Comparisons
The React Framework
Pros of Next.js
- Larger community and ecosystem, with more resources and third-party integrations
- More flexible, supporting various data sources and backend technologies
- Better performance optimization features, including automatic code splitting and image optimization
Cons of Next.js
- Steeper learning curve for developers new to React or server-side rendering
- Requires more configuration and setup for WordPress-specific features
- Less opinionated, which may lead to inconsistent coding practices across projects
Code Comparison
Next.js:
import { useEffect, useState } from 'react'
function HomePage() {
const [data, setData] = useState(null)
useEffect(() => {
fetch('/api/data').then(res => res.json()).then(setData)
}, [])
return <div>{data ? data.title : 'Loading...'}</div>
}
FaustJS:
import { useQuery } from '@faustjs/next'
import { client } from 'client'
function HomePage() {
const { data } = useQuery(() => client.posts().first())
return <div>{data?.post?.title ?? 'Loading...'}</div>
}
The code comparison shows that FaustJS provides a more streamlined approach for working with WordPress data, while Next.js offers a more generic setup that can be adapted to various data sources.
The best React-based framework with performance, scalability and security built in.
Pros of Gatsby
- Larger ecosystem with more plugins and themes
- Better performance optimization out of the box
- More flexible, can be used with various data sources beyond WordPress
Cons of Gatsby
- Steeper learning curve, especially for developers new to React
- Longer build times for large sites
- More complex setup and configuration compared to FaustJS
Code Comparison
FaustJS:
import { usePost } from '@faustjs/next';
function Post() {
const { post } = usePost();
return <h1>{post.title}</h1>;
}
Gatsby:
import { graphql } from 'gatsby';
export const query = graphql`
query($id: String!) {
wpPost(id: { eq: $id }) {
title
}
}
`;
function Post({ data }) {
return <h1>{data.wpPost.title}</h1>;
}
FaustJS provides a more straightforward API for fetching WordPress data, while Gatsby requires GraphQL queries. Gatsby's approach offers more flexibility but can be more complex for simple use cases.
Both frameworks aim to simplify headless WordPress development, but they take different approaches. FaustJS focuses on ease of use and WordPress-specific features, while Gatsby offers a more general-purpose solution with broader capabilities beyond WordPress integration.
The library for web and native user interfaces.
Pros of React
- Larger community and ecosystem, with more resources and third-party libraries
- More versatile, can be used for various types of applications beyond WordPress
- Better performance for complex, dynamic user interfaces
Cons of React
- Steeper learning curve, especially for developers new to JavaScript frameworks
- Requires more setup and configuration for a complete application
- Less integrated with WordPress-specific features and workflows
Code Comparison
React:
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
const element = <Welcome name="Sara" />;
ReactDOM.render(element, document.getElementById('root'));
FaustJS:
import { useQuery, gql } from '@apollo/client';
const GET_POST = gql`
query GetPost($id: ID!) {
post(id: $id) {
title
content
}
}
`;
function Post({ id }) {
const { loading, error, data } = useQuery(GET_POST, { variables: { id } });
// Render post data
}
Summary
React is a more general-purpose JavaScript library for building user interfaces, while FaustJS is specifically designed for WordPress development using React and GraphQL. React offers more flexibility and a larger ecosystem, but FaustJS provides a more streamlined experience for WordPress-specific projects with built-in integrations and optimizations.
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
Pros of Vue
- More mature and widely adopted framework with a larger ecosystem
- Flexible and scalable for various project sizes and complexities
- Extensive documentation and community support
Cons of Vue
- Steeper learning curve for developers new to frontend frameworks
- Potential for larger bundle sizes in complex applications
- Less opinionated, which may lead to inconsistencies in large teams
Code Comparison
Vue component example:
<template>
<div>{{ message }}</div>
</template>
<script>
export default {
data() {
return {
message: 'Hello, Vue!'
}
}
}
</script>
FaustJS component example:
import { useQuery } from '@faustjs/react';
export default function HelloWorld() {
const { data } = useQuery();
return <div>{data?.generalSettings?.title}</div>;
}
Vue focuses on a template-based approach with a clear separation of concerns, while FaustJS leverages React's component structure and WordPress data through GraphQL queries. Vue provides a more traditional frontend framework experience, whereas FaustJS is specifically tailored for WordPress headless development with React.
web development for the rest of us
Pros of Svelte
- Smaller bundle sizes and faster runtime performance due to compile-time optimization
- Simpler, more intuitive syntax with less boilerplate code
- Built-in state management and reactivity without additional libraries
Cons of Svelte
- Smaller ecosystem and community compared to React-based solutions
- Less mature tooling and third-party library support
- Limited server-side rendering capabilities out of the box
Code Comparison
Svelte component:
<script>
let count = 0;
function increment() {
count += 1;
}
</script>
<button on:click={increment}>
Clicks: {count}
</button>
FaustJS (React) component:
import React, { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Clicks: {count}
</button>
);
}
While both examples achieve similar functionality, Svelte's syntax is more concise and doesn't require importing React or using hooks. FaustJS, being based on React, offers a familiar ecosystem for WordPress developers but may require more setup and boilerplate code.
The Intuitive Vue Framework.
Pros of Nuxt
- More versatile framework for building various types of web applications, not limited to WordPress
- Larger community and ecosystem with more resources, plugins, and modules
- Better performance optimization out of the box, including automatic code splitting
Cons of Nuxt
- Steeper learning curve for developers new to Vue.js or modern JavaScript frameworks
- Less specialized for WordPress development compared to FaustJS
- May require more configuration and setup for specific use cases
Code Comparison
FaustJS (WordPress-specific):
import { usePost } from '@faustjs/next';
function Post() {
const { post } = usePost();
return <h1>{post.title}</h1>;
}
Nuxt (General-purpose):
<template>
<h1>{{ post.title }}</h1>
</template>
<script>
export default {
async asyncData({ $axios }) {
const post = await $axios.$get('/api/post');
return { post };
}
}
</script>
Summary
FaustJS is tailored for WordPress headless development, offering a more streamlined experience for WordPress-specific projects. Nuxt, on the other hand, is a more general-purpose framework that provides greater flexibility and a wider range of applications beyond WordPress. While FaustJS may be easier to adopt for WordPress developers, Nuxt offers more extensive features and community support for diverse web development needs.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Introduction
Faust.js is a toolkit for building Next.js applications for headless WordPress sites. Faust.js provides tooling to reduce the pains of building a headless WordPress site (namely around data fetching, authentication, previews, and SSR/SSG) while offering a pleasant experience for both developers and publishers.
System Requirements
- Node.js v16.0.0 or newer (v16.8.0 when using Next.js 13 and v18.17 when using Next.js 14).
- MacOS, Windows (including WSL), and Linux are supported.
Documentation
Visit https://faustjs.org/docs/ to view the full documentation.
Editing Docs
Docs are MD in docs
. Here are a couple things you should know!
-
Our Docs support Github Flavored Markdown (GFM).
-
Images should be stored along side the doc that uses them in an
images/
folder. -
Shared Images can be stored in a shared folder @
docs/images
-
Callouts: These are similar to block quotes or an aside but for various warnings, info, pro times, etc.
-
Code Blocks:
-
Required
- Specify a language:
```js
or`const inlineCode = [1,2,3];{:js}`
- Commands for a users terminal =
bash
- env files =
ini
- JavaScript =
js
- TypeScript =
ts
- GraphQL =
gql
- JSON =
json
- For a full list see: https://shiki.style/languages
- Commands for a users terminal =
- Add line numbers to any complex code.
ini
andbash
don't need to show line numbers generally.```js showLineNumbers
- Complete files should have a file names
```js title="pages/_app.js
- Specify a language:
-
Optional
-
Lines can be highlighted in code blocks
```js {1,3-5}
. There are a variety of advanced highlighting methods, see: https://rehype-pretty.pages.dev/#highlight-lines -
Lines may be diffed in a code block:
console.log('hewwo') // [!code --] console.log('hello') // [!code ++] console.log('goodbye')
-
-
WordPress Plugin (FaustWP)
There are two key parts to Faust.js: the NPM packages and the WordPress plugin. To take full advantage of headless, you will need to install the plugin in addition to the npm packages.
You can download and install FaustWP from the WordPress Plugin Directory, or by using the zip linked below.
Community
To chat with other Faust.js users and the headless community as a whole, you can join the WP Engine Developers Discord.
Additionally, if you have questions or ideas, please share them on GitHub Discussions.
Contributing
There are many ways to contribute to this project.
- Discuss open issues to help define the future of the project.
- Submit bugs and help us verify fixes as they are checked in.
- Review and discuss the source code changes.
- Contribute bug fixes
Contributor License Agreement
All external contributors to WP Engine products must have a signed Contributor License Agreement (CLA) in place before the contribution may be accepted into any WP Engine codebase.
- Submit your name and email
- ð Sign the CLA emailed to you
- ð¥ Receive copy of signed CLA
â¤ï¸ Thank you for helping us fulfill our legal obligations in order to continue empowering builders through headless WordPress.
Top Related Projects
The React Framework
The best React-based framework with performance, scalability and security built in.
The library for web and native user interfaces.
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
web development for the rest of us
The Intuitive Vue Framework.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot