x0
Document & develop React components without breaking a sweat.
Features
- Zero-config
- No plugins
- Components over configuration
- Use markdown, MDX, or React components
- Automatic file system based routing
- Completely customizable
- Export static sites
- Works as an isolated development environment
Getting Started
x0 renders a directory of React components, automatically handling routing based on filename.
Create a docs
folder and add an index.js
file.
Start a development server by running:
To add more pages, add a new component for each route. For example, create an about page:
The about page should now render when navigating to <http://localhost:8080/about>.
Isolated development environment
Options:
-o --open Open dev server in default browser
-p --port Custom port for dev server
-t --template Path to custom HTML template
--webpack Path to custom webpack configuration
Static Build
Export static HTML and client-side bundle
Export static HTML without bundle
Options
-d --out-dir Output directory (default dist)
-s --static Output static HTML without JS bundle
-t --template Path to custom HTML template
--webpack Path to custom webpack configuration
Fetching Data
Use the async getInitialProps
static method to fetch data for static rendering.
This method was inspired by [Next.js][nextjs].
Custom App
A custom App
component can be provided by including an _app.js
file.
The App
component uses the render props pattern to provide additional state and props to its child routes.
Layouts
The App
component can also be used to provide a common layout for all routes.
CSS-in-JS
x0 supports server-side rendering for [styled-components][sc] and [emotion][emotion] with zero configuration.
Styled Components
To enable CSS rendering for static export, ensure that styled-components
is installed as a dependency in your package.json
Emotion
Ensure emotion
is installed as a dependency in your package.json
Configuration
Default options can be set in the x0
field in package.json
.
Head content
Head elements such as <title>
, <meta>
, and <style>
can be configured with the x0
field in package.json
.
Custom HTML Template
A custom HTML template can be passed as the template
option.
Routing
x0 creates routes based on the file system, using [react-router][react-router].
To set the base URL for static builds, use the basename
option.
Links
To link between different components, install react-router-dom
and use the Link
component.
JSX Format
x0 includes support for the Compositor JSX file format.
MDX Format
x0 includes support for the MDX file format.
webpack
Webpack configuration files named webpack.config.js
will automatically be merged with the built-in configuration, using webpack-merge.
To use a custom filename, pass the file path to the --webpack
flag.
See the example.