{"id":13398066,"url":"https://github.com/c8r/x0","last_synced_at":"2025-05-15T05:07:12.224Z","repository":{"id":40005072,"uuid":"103340952","full_name":"c8r/x0","owner":"c8r","description":"Document \u0026 develop React components without breaking a sweat","archived":false,"fork":false,"pushed_at":"2019-11-06T18:22:27.000Z","size":23882,"stargazers_count":1708,"open_issues_count":32,"forks_count":65,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-05-06T13:14:35.989Z","etag":null,"topics":["components","compositor","design-systems","development-environment","docs","documentation","isolated","jsx","markdown","mdx","react","static-site-generator","testing","ui","webpack","zero-configuration"],"latest_commit_sha":null,"homepage":"https://compositor.io/x0/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/c8r.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-13T02:00:34.000Z","updated_at":"2025-03-20T05:36:19.000Z","dependencies_parsed_at":"2022-06-26T06:01:03.722Z","dependency_job_id":null,"html_url":"https://github.com/c8r/x0","commit_stats":null,"previous_names":[],"tags_count":83,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c8r%2Fx0","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c8r%2Fx0/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c8r%2Fx0/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c8r%2Fx0/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/c8r","download_url":"https://codeload.github.com/c8r/x0/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254276447,"owners_count":22043867,"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":["components","compositor","design-systems","development-environment","docs","documentation","isolated","jsx","markdown","mdx","react","static-site-generator","testing","ui","webpack","zero-configuration"],"created_at":"2024-07-30T18:02:04.920Z","updated_at":"2025-05-15T05:07:07.215Z","avatar_url":"https://github.com/c8r.png","language":"JavaScript","readme":"\n# x0\n\nDocument \u0026 develop React components without breaking a sweat\n\n[![Build Status][build-badge]][build]\n\n```sh\nnpm install -g @compositor/x0\n```\n\n[build-badge]: https://img.shields.io/travis/c8r/x0/master.svg?style=flat-square\n[build]: https://travis-ci.org/c8r/x0\n\n\u003cimg src='docs/hello-x0.gif' class='demo-image' /\u003e\n\n## Features\n\n- Zero-config\n- No plugins\n- Components over configuration\n- Use markdown, MDX, or React components\n- Automatic file system based routing\n- Completely customizable\n- Export static sites\n- Works as an isolated development environment\n\nRead more about x0 in our [blog post](https://compositor.io/blog/x0-making-react-component-development-stupid-simple/).\n\n## Getting Started\n\nx0 renders a directory of React components, automatically handling routing based on filename.\nCreate a `docs` folder and add an `index.js` file.\n\n```jsx\n// index.js\nimport React from 'react'\n\nexport default class extends React.Component {\n  render () {\n    return (\n      \u003ch1\u003eHello\u003c/h1\u003e\n    )\n  }\n}\n```\n\nStart a development server by running:\n\n```sh\nx0 docs --open\n```\n\nTo add more pages, add a new component for each route. For example, create an about page:\n\n```jsx\n// about.js\nimport React from 'react'\n\nexport default props =\u003e\n  \u003ch1\u003eAbout\u003c/h1\u003e\n```\n\nThe about page should now render when navigating to  \u003chttp://localhost:8080/about\u003e.\n\n## Isolated development environment\n\n```sh\nx0 docs\n```\n\nOptions:\n\n```\n-o --open       Open dev server in default browser\n-p --port       Custom port for dev server\n-t --template   Path to custom HTML template\n--webpack       Path to custom webpack configuration\n```\n\n```sh\nx0 docs -op 8080\n```\n\n\n## Static Build\n\nExport static HTML and client-side bundle\n\n```sh\nx0 build docs\n```\n\nExport static HTML without bundle\n\n```sh\nx0 build docs --static\n```\n\nOptions\n\n```\n-d --out-dir    Output directory (default dist)\n-s --static     Output static HTML without JS bundle\n-t --template   Path to custom HTML template\n--webpack       Path to custom webpack configuration\n```\n\n\n## Fetching Data\n\nUse the async `getInitialProps` static method to fetch data for static rendering.\nThis method was inspired by [Next.js][nextjs].\n\n```jsx\nconst Index = props =\u003e (\n  \u003ch1\u003eHello {props.data}\u003c/h1\u003e\n)\n\nIndex.getInitialProps = async () =\u003e {\n  const fetch = require('isomorphic-fetch')\n  const res = await fetch('http://example.com/data')\n  const data = await res.json()\n\n  return { data }\n}\n```\n\n## Custom App\n\nA custom `App` component can be provided by including an `_app.js` file.\nThe `App` component uses the [render props][render-props] pattern to provide additional state and props to its child routes.\n\n[render-props]: https://reactjs.org/docs/render-props.html\n\n```jsx\n// example _app.js\nimport React from 'react'\n\nexport default class extends React.Component {\n  state = {\n    count: 0\n  }\n\n  update = fn =\u003e this.setState(fn)\n\n  render () {\n    const { render, routes } = this.props\n\n    return render({\n      ...this.state,\n      decrement: () =\u003e this.update(s =\u003e ({ count: s.count - 1 })),\n      increment: () =\u003e this.update(s =\u003e ({ count: s.count + 1 }))\n    })\n  }\n}\n```\n\n### Layouts\n\nThe `App` component can also be used to provide a common layout for all routes.\n\n```jsx\n// example _app.js\nimport React from 'react'\nimport Nav from '../components/Nav'\nimport Header from '../components/Header'\nimport Footer from '../components/Footer'\n\nexport default class extends React.Component {\n  render () {\n    const {\n      location,\n      render,\n      routes\n    } = this.props\n\n    const route = routes.find(route =\u003e route.path === location.pathname)\n\n    return (\n      \u003cReact.Fragment\u003e\n        \u003cNav /\u003e\n        \u003cHeader\n          route={route}\n        /\u003e\n        {render()}\n        \u003cFooter /\u003e\n      \u003c/React.Fragment\u003e\n    )\n  }\n}\n```\n\n## CSS-in-JS\n\nx0 supports server-side rendering for [styled-components][sc] and [emotion][emotion] with zero configuration.\n\n### Styled Components\n\nTo enable CSS rendering for static export, ensure that `styled-components` is installed as a dependency in your `package.json`\n\n```json\n\"dependencies\": {\n  \"styled-components\": \"^3.2.6\"\n}\n```\n\n### Emotion\n\nEnsure `emotion` is installed as a dependency in your `package.json`\n\n```json\n\"dependencies\": {\n  \"emotion\": \"^9.1.3\"\n}\n```\n\n## Configuration\n\nDefault options can be set in the `x0` field in `package.json`.\n\n```json\n\"x0\": {\n  \"static\": true,\n  \"outDir\": \"site\",\n  \"title\": \"Hello\",\n}\n```\n\n## Head content\n\nHead elements such as `\u003ctitle\u003e`, `\u003cmeta\u003e`, and `\u003cstyle\u003e` can be configured with the `x0` field in `package.json`.\n\n```json\n\"x0\": {\n  \"title\": \"My Site\",\n  \"meta\": [\n    { \"name\": \"twitter:card\", \"content\": \"summary\" },\n    { \"name\": \"twitter:image\", \"content\": \"kitten.png\" }\n  ],\n  \"links\": [\n    {\n      \"rel\": \"stylesheet\",\n      \"href\": \"https://fonts.googleapis.com/css?family=Roboto\"\n    }\n  ]\n}\n```\n\n## Custom HTML Template\n\nA custom HTML template can be passed as the `template` option.\n\n```json\n\"x0\": {\n  \"template\": \"./html.js\"\n}\n```\n\n```js\n// example template\nmodule.exports = ({\n  html,\n  css,\n  scripts,\n  title,\n  meta = [],\n  links = [],\n  static: isStatic\n}) =\u003e `\u003c!DOCTYPE html\u003e\n\u003chead\u003e\n  \u003ctitle\u003e{title}\u003c/title\u003e\n  ${css}\n\u003c/head\u003e\n\u003cdiv id=root\u003e${html}\u003c/div\u003e\n${scripts}\n`\n```\n\n### Routing\n\nx0 creates routes based on the file system, using [react-router][react-router].\nTo set the base URL for static builds, use the `basename` option.\n\n```json\n\"x0\": {\n  \"basename\": \"/my-site\"\n}\n```\n\n#### Links\n\nTo link between different components, install `react-router-dom` and use the `Link` component.\n\n```sh\nnpm i react-router-dom\n```\n\n```js\nimport React from 'react'\nimport { Link } from 'react-router-dom'\n\nexport default () =\u003e (\n  \u003cdiv\u003e\n    \u003ch1\u003eHome\u003c/h1\u003e\n    \u003cnav\u003e\n      \u003cLink to='/'\u003eHome\u003c/Link\u003e\n      \u003cLink to='/about'\u003eAbout\u003c/Link\u003e\n    \u003c/nav\u003e\n  \u003c/div\u003e\n)\n```\n\n### JSX Format\n\nx0 includes support for the Compositor JSX file format.\n\n```jsx\n---\ntitle: Hello\n---\nimport { Box, Heading } from 'rebass'\n\n\u003cBox px={2} py={4}\u003e\n  \u003cHeading\u003e\n    {frontMatter.title}\n  \u003c/Heading\u003e\n\u003c/Box\u003e\n```\n\n### MDX Format\n\nx0 includes support for the [MDX][mdx] file format.\n\n```mdx\nimport { Box } from 'rebass'\n\n# Hello MDX\n\n\u003cBox p={4} bg='tomato'\u003e\n  Beep Boop\n\u003c/Box\u003e\n```\n\n### webpack\n\nWebpack configuration files named `webpack.config.js` will automatically be merged with the built-in configuration, using [webpack-merge][webpack-merge].\nTo use a custom filename, pass the file path to the `--webpack` flag.\n\n```js\n// webpack.config.js example\nmodule.exports = {\n  module: {\n    rules: [\n      { test: /\\.txt$/, loader: 'raw-loader' }\n    ]\n  }\n}\n```\n\nSee the [example](https://github.com/c8r/x0/tree/master/examples/webpack-config).\n\n#### Related\n\n- [Compositor JSX][jsx-loader]\n- [MDX][mdx]\n- [React Router][react-router]\n- [Mini HTML Webpack Plugin][mini-html]\n- [Styled Components][sc]\n- [Emotion][emotion]\n- [webpack][webpack]\n- [Create React App](https://github.com/facebookincubator/create-react-app)\n- [Next.js][nextjs]\n- [Gatsby][gatsby]\n- [React-Static][react-static]\n\n---\n\n[Made by Compositor](https://compositor.io/)\n|\n[MIT License](LICENSE.md)\n\n[jsx-loader]: https://github.com/c8r/jsx-loader\n[mdx]: https://github.com/mdx-js/mdx\n[nextjs]: https://github.com/zeit/next.js\n[react-router]: https://github.com/ReactTraining/react-router\n[mini-html]: https://github.com/styleguidist/mini-html-webpack-plugin\n[sc]: https://github.com/styled-components/styled-components\n[emotion]: https://github.com/emotion-js/emotion\n[glamorous]: https://github.com/paypal/glamorous\n[glamor]: https://github.com/threepointone/glamor\n[gatsby]: https://github.com/gatsbyjs/gatsby\n[react-static]: https://github.com/nozzle/react-static\n[react-loadable]: https://github.com/thejameskyle/react-loadable\n[webpack-merge]: https://github.com/survivejs/webpack-merge\n[webpack]: https://webpack.js.org\n\n","funding_links":[],"categories":["JavaScript","*.js","webpack"],"sub_categories":["React"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc8r%2Fx0","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc8r%2Fx0","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc8r%2Fx0/lists"}