Skip to content

wardy/cool-story-bro

Repository files navigation

Cool Story Bro

A massively over engineered app to print random versions of the phrase 'Cool Story Bro'. Build with the React Redux Starter Kit.

Features

Usage

Before delving into the descriptions of each available npm script, here's a brief summary of the three which will most likely be your bread and butter:

  • Doing live development? Use npm start to spin up the dev server.
  • Compiling the application to disk? Use npm run compile.
  • Deploying to an environment? npm run deploy can help with that.

Great, now that introductions have been made here's everything in full detail:

npm run... Description
start Spins up Koa server to serve your app at localhost:3000. HMR will be enabled in development.
compile Compiles the application to disk (~/dist by default).
dev Same as npm start, but enables nodemon to automatically restart the server when server-related code is changed.
dev:nw Same as npm run dev, but opens the redux devtools in a new window.
dev:no-debug Same as npm run dev but disables redux devtools.
test Runs unit tests with Karma and generates a coverage report.
test:dev Runs Karma and watches for changes to re-run tests; does not generate coverage reports.
deploy Runs linter, tests, and then, on success, compiles your application to disk.
deploy:dev Same as deploy but overrides NODE_ENV to "development".
deploy:prod Same as deploy but overrides NODE_ENV to "production".
flow:check Analyzes the project for type errors.
lint Lint all .js files.
lint:fix Lint and fix all .js files. Read more on this.

Configuration

Basic project configuration can be found in ~/config/_base.js. Here you'll be able to redefine your src and dist directories, adjust compilation settings, tweak your vendor dependencies, and more. For the most part, you should be able to make changes in here without ever having to touch the webpack build configuration.

If you need environment-specific overrides (useful for dynamically setting API endpoints, for example), create a file with the name of target NODE_ENV prefixed by an _ in ~/config (e.g. ~/config/_production.js). This can be entirely arbitrary, such as NODE_ENV=staging where the config file is ~/config/_staging.js.

Common configuration options:

Key Description
dir_src application source code base path
dir_dist path to build compiled application to
server_host hostname for the Koa server
server_port port for the Koa server
compiler_css_modules whether or not to enable CSS modules
compiler_devtool what type of source-maps to generate (set to false/null to disable)
compiler_vendor packages to separate into to the vendor bundle

Structure

The folder structure provided is only meant to serve as a guide, it is by no means prescriptive. It is something that has worked very well for me and my team, but use only what makes sense to you.

.
├── bin                      # Build/Start scripts
├── blueprints               # Blueprint files for redux-cli
├── build                    # All build-related configuration
│   └── webpack              # Environment-specific configuration files for webpack
├── config                   # Project configuration settings
├── interfaces               # Type declarations for Flow
├── server                   # Koa application (uses webpack middleware)
│   └── main.js              # Server application entry point
├── src                      # Application source code
│   ├── components           # Generic React Components (generally Dumb components)
│   ├── containers           # Components that provide context (e.g. Redux Provider)
│   ├── layouts              # Components that dictate major page structure
│   ├── redux                # Redux-specific pieces
│   │   ├── modules          # Collections of reducers/constants/actions
│   │   └── utils            # Redux-specific helpers
│   ├── routes               # Application route definitions
│   ├── static               # Static assets (not imported anywhere in source code)
│   ├── styles               # Application-wide styles (generally settings)
│   ├── views                # Components that live at a route
│   └── main.js              # Application bootstrap and rendering
└── tests                    # Unit tests

Webpack

Vendor Bundle

You can redefine which packages to bundle separately by modifying compiler_vendor in ~/config/_base.js. These default to:

[
  'history',
  'react',
  'react-redux',
  'react-router',
  'react-router-redux',
  'redux'
]

Webpack Root Resolve

Webpack is configured to make use of resolve.root, which lets you import local packages as if you were traversing from the root of your ~/src directory. Here's an example:

// current file: ~/src/views/some/nested/View.js

// What used to be this:
import SomeComponent from '../../../components/SomeComponent'

// Can now be this:
import SomeComponent from 'components/SomeComponent' // Hooray!

Globals

These are global variables available to you anywhere in your source code. If you wish to modify them, they can be found as the globals key in ~/config/_base.js. When adding new globals, also add them to ~/.eslintrc.

Variable Description
process.env.NODE_ENV the active NODE_ENV when the build started
__DEV__ True when process.env.NODE_ENV is development
__PROD__ True when process.env.NODE_ENV is production
__TEST__ True when process.env.NODE_ENV is test
__DEBUG__ True when process.env.NODE_ENV is development and cli arg --no_debug is not set (npm run dev:no-debug)
__BASENAME__ npm history basename option

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published