x0
Zero-config React development environment and static site generator.
Features
- Zero-config
- Hot-loading development environment
- Works with virtually any React component*
- No confusing APIs
- Automatic file system based routing
- Exports static HTML
- Exports JS bundles
- Works with CSS-in-JS libraries like [styled-components][sc] and [emotion][emotion]
- Support for async data fetching
* Custom webpack configuration is required for components that rely on webpack-based features
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][jsx-loader] file format.
MDX Format
x0 includes support for the [MDX][mdx] file format.
webpack
Webpack configuration files named webpack.config.js
will automatically be merged with the built-in configuration, using [webpack-merge][webpack-merge].
To use a custom filename, pass the file path to the --webpack
flag.
See the example.