{"id":13527043,"url":"https://github.com/shortlist-digital/tapestry-wp","last_synced_at":"2025-04-01T09:31:01.779Z","repository":{"id":65514542,"uuid":"67409665","full_name":"shortlist-digital/tapestry-wp","owner":"shortlist-digital","description":"Universal JavaScript Application for rendering React front-ends via the Wordpress API","archived":false,"fork":false,"pushed_at":"2018-04-08T05:15:00.000Z","size":3108,"stargazers_count":30,"open_issues_count":8,"forks_count":2,"subscribers_count":5,"default_branch":"develop","last_synced_at":"2025-03-23T04:32:50.052Z","etag":null,"topics":["react","wordpress"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shortlist-digital.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-05T09:58:42.000Z","updated_at":"2023-08-24T15:02:00.000Z","dependencies_parsed_at":"2023-01-26T21:05:19.404Z","dependency_job_id":null,"html_url":"https://github.com/shortlist-digital/tapestry-wp","commit_stats":null,"previous_names":[],"tags_count":113,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shortlist-digital%2Ftapestry-wp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shortlist-digital%2Ftapestry-wp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shortlist-digital%2Ftapestry-wp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shortlist-digital%2Ftapestry-wp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shortlist-digital","download_url":"https://codeload.github.com/shortlist-digital/tapestry-wp/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246615928,"owners_count":20806029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","wordpress"],"created_at":"2024-08-01T06:01:39.790Z","updated_at":"2025-04-01T09:31:00.276Z","avatar_url":"https://github.com/shortlist-digital.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://cdn.rawgit.com/shortlist-digital/tapestry-wp/master/logo/tapestry-logo-glyph.svg\" height=\"100\" \u003e\n  \u003cbr\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://www.npmjs.org/package/tapestry-wp\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/tapestry-wp.svg?style=flat\" alt=\"npm\"\u003e\u003c/a\u003e \u003ca href=\"https://circleci.com/gh/shortlist-digital/tapestry-wp/tree/master\"\u003e\u003cimg src=\"https://circleci.com/gh/shortlist-digital/tapestry-wp/tree/master.svg?style=shield\" alt=\"circleci\"\u003e\u003c/a\u003e \u003ca href=\"https://snyk.io/test/github/shortlist-digital/tapestry-wp\"\u003e\u003cimg src=\"https://snyk.io/test/github/shortlist-digital/tapestry-wp/badge.svg\" alt=\"snyk\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# Tapestry\n\nAn opinionated React SPA service for the WordPress Rest API. Create React components and let Tapestry handle the data loading, server rendering, JavaScript bundling and more.\n\n## Features\n\n- Data handling\n- Server rendered React\n- Small, secure Node server through Hapi\n- CSS-in-JS out of the box\n- Hot reloading\n- Production ready\n\n## Installation\n\n`yarn add tapestry-wp react react-dom`\n\n## Usage\n\nTapestry has a couple of commands to handle building and running the project, you can pop these into your NPM scripts.\n\n`tapestry` will create the client/server bundles and run the server in development mode, `tapestry build` will create the client and server bundles in production mode and `tapestry start` will run the server in production mode.\n\n```json\n{\n  \"scripts\": {\n    \"start\": \"tapestry\",\n    \"build\": \"tapestry build\",\n    \"start:prod\": \"tapestry start\"\n  }\n}\n```\n\nCreate a `tapestry.config.js` in the root of your project and export an object with your WordPress site URL and routes or components to render.\n\n```js\nimport Post from './components/post'\nimport Page from './components/page'\n\nexport default {\n  siteUrl: 'http://your-wordpress.url',\n  components: { Post, Page }\n}\n```\n\nThese components will match the default WordPress permalink routes for each page type. e.g. `/2017/12/08/a-post-slug`. You can override these default routes by adding a `routes` array to your config.\n\nEach route requires a `path` and a `component`, to access data from WordPress pass in an `endpoint`\n\n```js\nimport Post from './components/post'\nimport Page from './components/page'\n\nexport default {\n  siteUrl: 'http://your-wordpress.url',\n  routes: [{\n    path: '/:slug/:id',\n    endpoint: id =\u003e `posts/${id}`,\n    component: Post\n  }, {\n    path: '/about/:slug',\n    endpoint: slug =\u003e `pages?filter=${slug}`,\n    component: Page\n  }]\n}\n```\n\nOnce these are set up, you're free to start building your site and writing React components.\n\n## Options\n\n`tapestry.config.js` has a number of options to modify the Tapestry bundling and server.\n\n```js\n{\n  // [string] URL for your WordPress instance\n  siteUrl: '',\n  // [object] Container for React components\n  components: {\n    // [function] React components for rendering a post, page, category\n    Category,\n    CustomError,\n    FrontPage,\n    Page,\n    Post\n  },\n  // [array] Container for route objects\n  routes: [\n    {\n      // [string] Path to match component\n      path: '',\n      path: '/path/:dynamic-path(/:optional-path)'\n      \n      // [function] React component to render\n      component: () =\u003e {},\n      // [function] import React component to render, this will code-split all JS from this route\n      getComponent: () =\u003e import(),\n      // [any] Source for WordPress API data, can be one of array, object or string, can also be a function that returns any of those data-types. When used as a function it has access to params from the path\n      endpoint: 'posts',\n      endpoint: ['posts', 'pages'],\n      endpoint: { posts: 'posts', pages: 'pages' },\n      endpoint: (id) =\u003e `posts/${id}`,\n      endpoint: (id) =\u003e [`posts/${id}`, `pages/${id}`],\n      endpoint: (id) =\u003e { posts: `posts/${id}`, pages: `pages/${id}` }\n      // [object] Container for route specific options\n      options: {\n        // [boolean] If WordPress API returns an array, allow the array response to be empty\n        allowEmptyResponse: false,\n        // [function] A React component to handle the surrounding document\n        customDocument: ({ html, css, ids, asyncProps, assets }) =\u003e {}\n      }\n    }\n  ],\n  // [array] Paths to proxy through to the WordPress URL\n  proxyPaths: [],\n  // [object] Redirects from key to value e.g. { 'from': 'to' }\n  redirectPaths: {},\n  // [string] [uri] URL for JSON redirects file, will get picked up on server boot\n  redirectsEndpoint: '',\n  // [function] Runs when a route has updated and passes the API response\n  onPageUpdate: (response) =\u003e {},\n  // [object] Container for site options\n  options: {\n    // [string] 'localhost', '0.0.0.0'\n    host: '',\n    // [number] 3030\n    port: 3030,\n    // [string] Theme colour for progress bar\n    progressBarColor: '',\n    // [boolean] Registers https Hapi plugin\n    forceHttps: false,\n    // [boolean] Wordpress.com hosting configuration\n    wordpressDotComHosting: false\n  }\n}\n```\n\n## Commands\n\nTapestry comes with a series of commands to control compiling and running the server.\n\n- `tapestry` - Compiles the server/client JavaScript and boots the server in development mode\n- `tapestry build` - Compiles the server/client JavaScript\n- `tapestry start` - Runs any server/client bundles\n- `tapestry hot` - Boots a hot-reloading Tapestry instance\n- `tapestry init` - Bootstraps a simple Tapestry project with a `tapestry.config.js` and some components\n\n## Custom compilation\n\n### Babel\nIf you need to modify the default Tapestry `babel` configuration, you can create a `.babelrc` file in the root of your project and Tapestry will use it to override any default options. You will need to define the `react` preset and `transform-object-rest-spread`, `syntax-dynamic-import` plugins.\n\n### Webpack\nTo modify the Webpack config you can create a `webpack.config.js` in the root of your project that exports a modified config.\n\nAn example config that adds an alias for `partials`:\n\n```js\nconst path = require('path')\nconst merge = require('webpack-merge')\n\nmodule.exports = (default, options, webpack) =\u003e {\n  const custom = {\n    resolve: {\n      alias: {\n        partials: path.resolve(\n          __dirname, 'components', 'partials'\n        )\n      }\n    }\n  }\n  merge(default, custom)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshortlist-digital%2Ftapestry-wp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshortlist-digital%2Ftapestry-wp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshortlist-digital%2Ftapestry-wp/lists"}