cj-scripts v1.0.0
cj-scripts 💻
Scripts for front end gangsters writing React apps.
What is it?
cj-scripts is a CLI that abstracts linting, formatting, transpiling, testing, building, and serving React projects into one dependency. Think of it like a poor man's react-scripts.
Here are some things included:
- Webpack config for dev and prod
- Dev middleware attached to your Express application with hot reloading
- Babel configuration
.envfile support- Configured Jest testing
- Multi-core utilzation for production builds
How do I use it?
- Install it:
npm i cj-scriptsCreate a
.envfile at the root of your app for your environment variables.Add
cj-scripts/babelas a preset to your.babelrc(but Babel itself is not required):
{
"presets": ["cj-scripts/babel"]
}Create a
src/index.jsfile that bootstraps your client-side app.Export an Express application at
server/app.jscalledapp. This should probably route to your client-side app, serve static assets, and any other logic you might want (except for dev middleware, that's included when runningcj-scripts start).
import express from 'express';
export const app = express();
// your server logic...- Run any of the commands below within the context of your app (i.e. put them in your
package.jsonscripts)
Commands
cj-scripts start
- Start your Express app with development middleware attached.
- This command expects
src/index.jsas the bootstrap file for your client-side app. - By default this will look for a named export of an Express server/router called
appin/server/app.js, but this path can be changed with theCJ_SCRIPTS_APP_PATHenvironment variable. - The
PORTenvironment variable can also be used to dictate the port (the default value is3000).
cj-scripts test
- Fire up Jest in watch mode or optimized for CI based on the environment.
- You can add a file at
config/setupTests.jsin your app to run initialization code for testing (think Enzyme adapter setup or global overrides).
cj-scripts build
- Build the production assets into a
builddirectory at the root of your app. - The
PUBLIC_URLenvironment variable can be set to serve your app at a path other than the root.
cj-scripts start-prod
- Run your Express app in production mode using the
clustermodule to take advantage of multiple cores. - The
PUBLIC_URLenvironment variable can be set to serve your app at a path other than the root. - The
PORTenvironment variable can also be used to dictate the port (the default value is3000).
Utilities
import { getAppEnv } from 'cj-scripts'
const env = getAppEnv()You can use getAppEnv() to collect environment variables from a .env file at the root of your app.