Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Latest commit

 

History

History
228 lines (161 loc) · 9.96 KB

API.md

File metadata and controls

228 lines (161 loc) · 9.96 KB

API

All the configuration needed to customize vitamin is done through a .vitaminrc file at the root of your project.

Table of content

Path (<Route>|store=><Route>)

Root route of your application. This is the only mandatory element for running vitaminjs. You can export a function. If you do so, the function will be call with the redux store. Useful for registering listener before the application starts. You might want to do that only on client side (you can use the global IS_CLIENT for that).

Config option for redux, specified in the redux key of the config object.

Path Object

A path to a file exporting an object of reducers. TODO Print a nice warning when user export a simple reducer with combineReducer

Path Array

A path to a file exporting an array of redux middleware. By default, vitamin adds the router and redux-thunk middleware.

Path [ StoreEnhancers ]

A path to a file exporting an array of store enhancers.

Path

Path to a file exporting two functions.

  • stringify: State-> String
  • parse: String -> State

Used for transmetting the state computed by the server to the client. By default, it serialize the state with JSON. It should be good if you're doing Vanilla redux. If, however, you use some fancy structure in your state (for instance Immutable.js, you can specify a different parser and stringifier.

Config option for server side rendering, specified in the server key of the config object.

@deprecated host, use defaultHost instead

String

The default host of the node server, it is used if process.env.HOST is not defined.

String

The default host of the node server, it is used if process.env.HOST is not defined.

@deprecated port, use defaultPort instead

String | Integer

The default port on which the node server is listening, it is used if process.env.PORT is not defined.

String | Integer

The default port on which the node server is listening, it is used if process.env.PORT is not defined.

String

If you don't want to serve the static files with vitaminjs, but use a custom server instead, you can specify its URL here (usually it means you want to use a CDN, or that you don't not using server side rendering). [TODO : change name to staticAssetsPath]

Path [ koaMiddleware ]

Path to a file exporting an array of koa middlewares. Useful for additional logging, proxy request, authentication or other things on server.

Path (KoaRequest) -> ?Action

Path to a file exporting an createInitAction. Useful for populating the store on the server before rendering. request object is passed as a parameter to createInitAction. It must return an action or nothing. The action can be a thunk.

Path <ReactComponent>

You can customize the HTML layout rendered by the server (if you really need to).

####Props

  • head: The head from react-helmet
  • style: The CSS of the page as a string
  • children: The app itself (or the error pages)

Path <ReactComponent>

The page displayed when an error occurs.

Props

  • HTTPStatus: the error throwed. Useful for printing stack. Only passed when in dev mode.
  • request: The koa request object
  • error (optional): If the page is displayed because of an error thrown during rendering (500) you'll find here the javascript Error object (with the usual name, message and stack props)
  • state (optional): The redux state object, if it's present

Path (context: { HTTPStatus: Number, request: [KoaRequest], error: Error, state: ReduxState })

This function will be called server side when an error occurs during the application rendering. Useful for advanced logging.

Parameters

  • context: An object containing specifics about the error
    • HTTPStatus: the error throwed. Useful for printing stack. Only passed when in dev mode.
    • request: The koa request object
    • error (optional): If the page is displayed because of an error thrown during rendering (500) you'll find here the javascript Error object (with the usual name, message and stack properties)
    • state (optional): The redux state object, if it's present

String

The path relative to the application root where both server bundle is going to be generated. Default to ./build

String

Define the filename of the server bundle. It will be created at the root of server.buildPath. By default, it's server_bundle.js

String

You can specify a basepath for your vitaminjs application. It will be prepended to all the internal link inside your app. Useful for mounting your whole app on a subpath.

String

The path from which all the public ressources should be made available. If it's relative, the public folder will be mounted on it. It can also be absolute. It behave similarly to the webpack output.publicPath option. Default to assets.

Boolean (defaults true)

If true serve buildPath folder at publicPath's pathname.

Config options for the client

String

The path relative to the application root where the clients assets will be generated (bundle, files, sourcemaps...). This path will be served statically by vitamin server. Default to ./public

String

Define the filename of the client build. It is relative to build.path. You can include a hash, with the placeholder [hash]. Behave like webpack output.filename. By default, it's client_bundle.[hash].js

Path

Path to the service worker, if you have one. Vitaminjs will prepend a constant named serviceWorkerOption during the compilation. This constant will contains all the assets names generated during compilation. You'll have to cache them manually, register the service manually etc... This is juste a little helper. You can access the service worker under /<basePath>/<publicPath>/sw.js. Default to `false

Array<String>

Use browserslist to declare supported environments by performing queries like > 1%, last 2 versions. Default is >1%, last 4 versions, Firefox ESR, not ie < 9.

String

If you want to run your application without headers, you can define here the element ID where the app will append itself. By default, it's vitamin-app

Path

Make your .vitaminrc extends another vitamin config. It is useful in case you want to have a base configuration for multiple environments.

Globals

Two globals are available everywhere in your application : IS_SERVER and IS_CLIENT. When bundling your application vitaminjs will replace them with true/false depending on the environment.