• Stars
    star
    361
  • Rank 117,188 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A boilerplate written in ES6 using ReactJS (along with React Router and RefluxJS), SASS, Gulp, and Browserify.

react-rocket

Build Status devDependency Status

A boilerplate using ReactJS (along with React Router and RefluxJS), SASS, Gulp, and Browserify that also utilizes Gulp best practices from this resource.


Getting up and running

  1. Clone this repo from https://github.com/jakemmarsh/react-rocket-boilerplate.git
  2. Run npm install from the root directory
  3. Run gulp dev (may require installing Gulp globally npm install gulp -g)
  4. Your browser will automatically be opened and directed to the browser-sync proxy address
  5. To prepare assets for production, run the npm run build task (Note: the production task does not fire up the browser-sync server, and won't provide you with browser-sync's live reloading. Simply use gulp dev during development. More information below)

Now that gulp dev is running, the server is up as well and serving files from the /build directory. Any changes in the /app directory will be automatically processed by Gulp and the changes will be injected to any open browsers pointed at the proxy address.


This boilerplate uses the latest versions of the following libraries:

Along with many Gulp libraries (these can be seen in either package.json, or at the top of each task in /gulp/tasks/).


Running tests

  1. If you haven't already, follow steps 1 & 2 above
  2. If you haven't already run gulp dev or npm run build at least once, run npm run build
  3. Run all tests in the tests/ directory with the gulp test command
  • A single file can be run by specifing an -f flag: gulp test -f <PATH_TO_TEST_FILE>
    • In the PATH_TO_TEST_FILE, it is possible to omit the tests/ prefix, as well as the .test.js suffix. They will be automatically added if not detected.
Code coverage

When running tests, code coverage will be automatically calculated and output to an HTML file using the Istanbul library. These files can be seen in the generated coverage/ directory.


ReactJS

ReactJS is a "declarative, efficient, and flexible JavaScript library for building user interfaces."

  • "Just the UI: Lots of people use React as the V in MVC. Since React makes no assumptions about the rest of your technology stack, it's easy to try it out on a small feature in an existing project."
  • "Virtual DOM: React uses a virtual DOM diff implementation for ultra-high performance. It can also render on the server using Node.js — no heavy browser DOM required."
  • "Data flow: React implements one-way reactive data flow which reduces boilerplate and is easier to reason about than traditional data binding."

The ReactJS files are all located within /app/js, structured in the following manner:

/components
  - Footer.js (Simple, static footer component rendered on all pages.)
  - Header.js (Simple, static header component rendered on all pages.)
/pages
  - HomePage.js (Example home page, serving as the default route.)
  - NotFoundPage.js (Displayed any time the user requests a non-existent route.)
  - SearchPage.js (Example search page to demonstrate navigation and individual pages.)
/utils
  - APIUtils.js (General wrappers for API interaction via Superagent.)
  - AuthAPI.js (Example functions for user authorization via a remote API.)
App.js (The main container component, rendered to the DOM and then responsible for rendering all pages.)
index.js (The main javascript file watched by Browserify, responsible for requiring the app and running the router.)
Routes.js (Defines the routing structure, along with each individual route path and handler.)

Each module you add to your project should be placed in the appropriate directory, and required in the necessary files. Once required, they will be automatically detected and compiled by Browserify (discussed later).


RefluxJS

RefluxJS is a "simple library for unidirectional dataflow architecture inspired by ReactJS Flux."

"The pattern is composed of actions and data stores, where actions initiate new data to pass through data stores before coming back to the view components again. If a view component has an event that needs to make a change in the application's data stores, they need to do so by signalling to the stores through the actions available."

The RefluxJS files are also all locationed within /app/js, structured in the following manner:

/actions
  - CurrentUserActions.js (Possible actions relevant to the current user. i.e. `checkAuth`, `login`, and `logout`.)
/stores
  - CurrentUserStore.js (Responsible for storing the current user data, while listening to any `CurrentUserActions`.)

Each action or store you add to your project should be placed in the appropriate directory, and required in the necessary files. The necessary logic to trigger actions and listen to stores should also be added.


React Router

React Router is a "complete routing library for React." It uses the JSX syntax to easily define route URLs and handlers, providing an easy-to-understand architecture and thus makes it easy to add new pages and routes.

The relevant files are all located within /app/js, structured in the following manner:

/pages (Each individual page to handle the defined routes and be rendered inside the app.)
App.js (The main component which is rendered to the DOM and responsible for rendering the current page.)
index.js (The main javascript file watched by Browserify, requiring the app and running the router.)
Routes.js (Defines the routing structure, along with each individual route path and handler.)

Any pages added to your project should be placed within the app/js/pages directory, and be required and assigned to a route inside Routes.js. If more complex nesting is required, any page can have a new RouteHandler as a child component.


SASS

SASS, standing for 'Syntactically Awesome Style Sheets', is a CSS extension language adding things like extending, variables, and mixins to the language. This boilerplate provides a barebones file structure for your styles, with explicit imports into app/styles/main.scss. A Gulp task (discussed later) is provided for compilation and minification of the stylesheets based on this file.


Browserify

Browserify is a Javascript file and module loader, allowing you to require('modules') in all of your files in the same manner as you would on the backend in a node.js environment. The bundling and compilation is then taken care of by Gulp, discussed below.


Gulp

Gulp is a "streaming build system", providing a very fast and efficient method for running your build tasks.

Web Server

Gulp is used here to provide a very basic node/Express web server for viewing your application as you build. It serves static files from the build/ directory, leaving routing up to React Router. All Gulp tasks are configured to automatically reload the server upon file changes. The application is served to localhost:3000 once you run the gulp task. To take advantage of the fast live reload injection provided by browser-sync, you must load the site at the proxy address (which usually defaults to server port + 1, and within this boilerplate will by default be localhost:3001.)

Scripts

A number of build processes are automatically run on all of our Javascript files, run in the following order:

  • Browserify: The main build process run on any Javascript files. This processes any of the require('module') statements, compiling the files as necessary.
  • Babelify: This uses babelJS to provide support for ES6+ features, while simultaneously parsing and converting any existing JSX.
  • Debowerify: Parses require() statements in your code, mapping them to bower_components when necessary. This allows you to use and include bower components just as you would npm modules.
  • Uglifyify: This will minify the file created by Browserify and ngAnnotate.

The resulting file (main.js) is placed inside the directory /build/js/.

Styles

Just one task is necessary for processing our SASS files, and that is gulp-sass. This will read the main.scss file, processing and importing any dependencies and then minifying the result. This file (main.css) is placed inside the directory /build/css/.

  • gulp-autoprefixer: Gulp is currently configured to run autoprefixer after compiling the scss. Autoprefixer will use the data based on current browser popularity and property support to apply prefixes for you. Autoprefixer is recommended by Google and used in Twitter, WordPress, Bootstrap and CodePen.
Images

Any images placed within /app/images will be automatically copied to the build/images directory. If running npm run build, they will also be compressed via imagemin.

Watching files

All of the Gulp processes mentioned above are run automatically when any of the corresponding files in the /app directory are changed, and this is thanks to our Gulp watch tasks. Running gulp dev will begin watching all of these files, while also serving to localhost:3000, and with browser-sync proxy running at localhost:3001 (by default).

Production Task

Just as there is the gulp dev task for development, there is also a npm run build task for putting your project into a production-ready state. This will run each of the tasks, while also adding the image minification task discussed above. There is also an empty gulp deploy task that is included when running the production task. This deploy task can be fleshed out to automatically push your production-ready site to your hosting setup.

Reminder: When running the production task, gulp will not fire up the express server and serve your index.html. This task is designed to be run before the deploy step that may copy the files from /build to a production web server.

More Repositories

1

angularjs-gulp-browserify-boilerplate

Boilerplate using AngularJS, SASS, Gulp, and Browserify and utilizing best practices.
JavaScript
1,033
star
2

react-tour-guide

A ReactJS mixin to give new users a popup-based tour of your application.
JavaScript
152
star
3

neural-network-stock-predictor

Semester project for COS 470 (Artifical Intelligence) at the University of Maine.
Python
88
star
4

expressed-boilerplate

A boilerplate for quickly building APIs on node.js and Express.
JavaScript
59
star
5

node-soundcloud

node.js wrapper for the Soundcloud SDK
JavaScript
32
star
6

grunt-requirejs-angularjs-sass-boilerplate

A boilerplate for Grunt, RequireJS, AngularJS, and SASS.
CSS
25
star
7

node-bandcamp

node.js (unofficial) Bandcamp API.
JavaScript
16
star
8

react-native-diff-view

A React Native module for parsing and displaying git diffs.
TypeScript
15
star
9

react-annotator

A React mixin to allow for user annotations directly on images.
JavaScript
14
star
10

acadeME

interactive eLearning platform for University of Maine senior capstone project
JavaScript
12
star
11

reddit-tumblr-bot

a Reddit-to-Tumblr bot in Python
Python
9
star
12

assemble-static-boilerplate

A boilerplate using Assemble and Gulp to quickly and efficiently create static websites.
JavaScript
5
star
13

playback-queue

A fully-featured and generic playback queue for music objects including history, shuffle, and repeat.
JavaScript
5
star
14

mono-ts-starter

A boilerplate for starting and publishing a TypeScript npm module.
JavaScript
2
star
15

ebs-setup

Custom build hooks and configuration for Elastic Beanstalk.
Shell
2
star
16

golang-api

A basic API in Go.
Go
1
star
17

craigslist.js

A Javascript API wrapper for craigslist.org.
JavaScript
1
star
18

gulp-git-status

A Gulp plugin for selectively including source files based on their Git status.
JavaScript
1
star
19

Gifft

A React-Native iOS app for managing upcoming occasions with reminders and gift ideas.
JavaScript
1
star
20

coyote-moves

Internal web app to visually search for fellow employees and initiate desk moves.
JavaScript
1
star
21

downloadr

A simple file-sharing web app built on the MEAN stack.
JavaScript
1
star
22

monolist-music-web

The web application for the now-defunct music app Monolist.
JavaScript
1
star
23

monolist-music-api

node.js server and Express API for the now-defunct music app Monolist.
JavaScript
1
star
24

jakemmarsh.github.io

source for my personal website, hosted on Github Pages
CSS
1
star
25

nftea

A simple dapp for minting NFTs on IPFS.
TypeScript
1
star