Skip to content
This repository was archived by the owner on Apr 11, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node server.js
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Following the lead of the famous [React Boilerplate]() project, this starter pro
We incorporate an ESLint configuration and follow strictly the [AirBnb JS & JSX style guides](https://github.com/airbnb/javascript).

# What is Feature First?
In most projects and frameworks, files are organized in a File type first fashion. For example, your tests exist in a test folder, your styles in a styles folder. This boilerplate takes a different approach.
In most projects and frameworks, files are organized in a File type first fashion. For example, your tests exist in a test folder, your styles in a styles folder. This boilerplate takes a different approach.

We encourage encapsulation of features by asking that you organize each feature into a seperate folder (feature-first). In React, this means that your containers and components exist in their own folders, along with literally every other file that pertains to that one component. Your actions, reducers, tests, styles, and everything else are all internal to the component they represent. By decoupling your features from the rest of your app, you set yourself up to reuse your UI components in future projects. You can thank us later!

Expand All @@ -35,13 +35,16 @@ To try the example application out or to use the project, follow the instruction

npm run start

Development server should be running at http://localhost:8080/
Your app will be served at: http://0.0.0.0:1337/

4. **Make build**
## Deployment
In order to deploy the app, a demo express server setup has been included. If you peak inside the server folder, you will see an example setup. The public folder includes all of the files that are generated when running the: `npm run deploy` script. This includes the production minified bundle.js, index.html and an app folder that includes all image assets.

npm run build
The express server can be run with `npm run serve:bundle`. This will start a static express server and serve the generated assets, just like you would in production. A Procfile is included, that will run the node server on [Heroku](https://heroku.com) automatically if you push your project to Heroku after running the `npm run deploy` command.

### File Structure
NOTE: the deployment script will place all your generated assets in the `server/public` folder, where they can be served in production.

## File Structure
* Some files left out for brevity. Please reference the files in the [Scalable React Boilerplate](https://github.com/RyanCCollins/feature-first-react-boilerplate) project for an example of the file structure. The application will ultimately be in use in a production web application project and more info will be posted here when we have production level examples.
```
.
Expand Down Expand Up @@ -88,30 +91,31 @@ To try the example application out or to use the project, follow the instruction

## Scripts
- **npm run setup**

Installs the application's dependencies
+ Installs the application's dependencies

- **npm run test**
+ Runs unit tests

Runs unit tests
- **npm run test:watch**
+ Watches for changes to run unit tests

Watches for changes to run unit tests
- **npm run build**
+ Bundles the application

Bundles the application
- **npm run dev**
+ Starts webpack development server

Starts webpack development server
- **npm run lint**
+ Runs the linter

Runs the linter
- **npm run deploy**
+ Creates the production ready files within the `/server/public` folder

Creates the production ready files
- **npm run clean**
+ Removes the bundled code and the production ready files

Removes the bundled code and the production ready files
- **npm run serve:bundle**
+ Serve production assets from the `/server/public` folder.

## Generators
The boilerplate contains generators for easy project scaffolding. At the moment, the generator has the following scaffold generating commands built in:
Expand Down Expand Up @@ -150,7 +154,7 @@ where <type_of_component> is one of: component, container or page.

The generators use the same feature-first file organization as the rest of the project, encapsulating components within their own folder.

#### **Gotchas**
### **Gotchas**
In order to get the import / export to work, the generator does some pattern matching of the comments in the files to place the new imports. Just don't delete the comments within the root level index.js file in each directory and things will work fine!

From `app/src/container/index.js` or `app/src/component/index.js`
Expand Down Expand Up @@ -221,6 +225,8 @@ which will pick up any file with the .test.js postfix and run it through Karma /
* [x] Add [Grommet](grommet.io) as an optional starter component library
* [x] Add Webpack stats plugin
* [x] Dogfood the project and iterate on suggestions
* [x] Setup production server configuration
* [ ] Add Jest as testing utility
* [ ] Create Docker container & automation scripts
* [ ] Write wiki / other documentation

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!doctype html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<title>Scalable React Boilerplate</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Raleway:400,300,700|Lato:400,300,700' rel='stylesheet' type='text/css'>
</head>
<body>
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
"generate:container": "plop --plopfile config/generators/index.js container",
"generate:page": "plop --plopfile config/generators/index.js page",
"lint": "eslint . --ext .js --ext .jsx; exit 0",
"deploy": "NODE_ENV=production webpack -p",
"deploy": "cross-env NODE_ENV=production webpack -p",
"start": "npm run dev",
"clean": "rm -rf app/dist app/build",
"setup": "npm install"
"setup": "npm install",
"serve:bundle": "cross-env NODE_ENV=production PORT=1337 node server.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -62,6 +63,7 @@
"babel-preset-stage-0": "^6.3.13",
"components": "^0.1.0",
"css-loader": "^0.23.0",
"express": "^4.14.0",
"expect": "^1.20.2",
"expect-jsx": "^2.6.0",
"file-loader": "^0.9.0",
Expand Down
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require("babel-core/register");
var app = require('./server/app');
19 changes: 19 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable */
const isDeveloping = process.env.NODE_ENV !== 'production';
const port = isDeveloping ? 1337 : process.env.PORT;
const path = require('path');
const express = require('express');
const app = express();

app.use(express.static(__dirname + '/public'));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'public/index.html'));
});

app.listen(port, '0.0.0.0', (err) => {
if (err) {
return console.warn(err);
}
return console.info(`==> 😎 Listening on port ${port}. Open http://0.0.0.0:${port}/ in your browser.`);
});
/* eslint-enable */
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions server/public/bundle.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions server/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<title>Scalable React Boilerplate</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Raleway:400,300,700|Lato:400,300,700' rel='stylesheet' type='text/css'>
</head>
<body>
<!-- The app will bootstrap into this div -->
<div id="app"></div>
<script src="/app/build/bundle.js"></script>
<script type="text/javascript" src="/bundle.js"></script></body>
</html>
189 changes: 189 additions & 0 deletions server/public/stats.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Visualizer from 'webpack-visualizer-plugin';
const ROOT_PATH = path.resolve(__dirname);

const env = process.env.NODE_ENV || 'development';
const PORT = process.env.PORT || 8080;
const PORT = process.env.PORT || 1337;
const HOST = '0.0.0.0'; // Set to localhost if need be.

module.exports = {
Expand Down Expand Up @@ -76,7 +76,7 @@ module.exports = {
},
},
output: {
path: process.env.NODE_ENV === 'production' ? path.resolve(ROOT_PATH, 'app/dist') : path.resolve(ROOT_PATH, 'app/build'),
path: process.env.NODE_ENV === 'production' ? path.resolve(ROOT_PATH, 'server/public') : path.resolve(ROOT_PATH, 'app/build'),
publicPath: '/',
filename: 'bundle.js',
},
Expand Down