Documentation
React Cosmos CLI

React Cosmos CLI

Add one or more of the following scripts to your package.json to start the Cosmos dev server, export a static build, or start the Cosmos dev server for a React Native project.

package.json
"scripts": {
  "cosmos": "cosmos",
  "cosmos-native": "cosmos-native",
  "cosmos-export": "cosmos-export"
}

cosmos

The cosmos command starts the dev server.

npm run cosmos
ArgumentDescription
--configSpecify a custom config path. By default Cosmos reads cosmos.config.json from your root directory.
--root-dirSpecify a root directory for your project. By default the root directory is the parent directory of your Cosmos config or the current working directory in the absence of a Cosmos config.
--lazyDynamically import user modules. By default all fixture and decorator modules are imported statically and bundled together.
--expose-importsExpose user imports and config required for the Cosmos renderer. Use with React Native and in custom integrations. When a path is specified it requires a file extension (eg. "src/cosmos.imports.ts").
--portConvenient way to override the Cosmos dev server port.

cosmos-native

The cosmos-native command starts the dev server for a React Native project.

npm run cosmos-native
ArgumentDescription
--configSpecify a custom config path. By default Cosmos reads cosmos.config.json from your root directory.
--root-dirSpecify a root directory for your project. By default the root directory is the parent directory of your Cosmos config or the current working directory in the absence of a Cosmos config.
--lazyDynamically import user modules. By default all fixture and decorator modules are imported statically and bundled together.
--portConvenient way to override the Cosmos dev server port.

--expose-imports isn't relevant here because imports are always exposed for React Native projects.

cosmos-export

The cosmos-export command generates a static export.

npm run cosmos-export
ArgumentDescription
--configSpecify a custom config path. By default Cosmos reads cosmos.config.json from your root directory.
--root-dirSpecify a root directory for your project. By default the root directory is the parent directory of your Cosmos config or the current working directory in the absence of a Cosmos config.
--lazyDynamically import user modules. By default all fixture and decorator modules are imported statically and bundled together.

The rest of the settings are customized using the large number of options in cosmos.config.json.