Skip to content

Commit bd3a084

Browse files
authored
Merge pull request #48 from iroy2000/allow-multiple-project-same-time
Allow to run multiple projects at same time
2 parents 1729ee8 + 24d7e26 commit bd3a084

File tree

6 files changed

+53
-24
lines changed

6 files changed

+53
-24
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Basic
9797
1. [Folder Structure](#folder-structure)
9898
1. [Production Readiness](#production-readiness)
9999
1. [Configuration](#configuration)
100+
1. [Port Configuration](#port-configuration)
100101
1. [Installing Dependencies](#installing-dependencies)
101102

102103
Advanced
@@ -303,6 +304,16 @@ __Just remember__, `.env` file suppose to keep your secret, and prevent your fro
303304

304305
We are using [dotenv](https://github.com/motdotla/dotenv) for the `.env` feature, they have pretty good documentation.
305306

307+
## Port Configuration
308+
There will be a chance that you will need your port to be other than `8080`. For example, your local backend service might already take `8080`; Or you want to run multiple project, one on `8080` and one on `80801`.
309+
310+
If you are running one project that needs a different port, you can just modify one place
311+
1) `default.json` --> `port` section.
312+
313+
But if you want to run multiple projects at the same time, you will need to configure ports in two places
314+
1) `default.json` --> `port`
315+
2) Dashboard port --> `package.json` --> `dev` ( default dashboard port is `9901` )
316+
306317
## Installing Dependencies
307318

308319
We are using `npm` in this project, so if you would like to install a dependencies, for example, D3, you can do something like the following :-

bin/commands.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ const colors = require('colors');
55
const host = config.get('host') || 'localhost';
66
const port = config.get('port') || '8080';
77

8+
console.log('using settings:');
9+
console.log('\thost:', host);
10+
console.log('\tport:', port);
11+
812
const option = process.argv[2];
913

1014
switch (option) {
1115
case 'lint':
1216
shell.exec('cross-env eslint src/js/** server/** --format node_modules/eslint-friendly-formatter . --ext .js --ext .jsx --cache; exit 0');
1317
break;
1418
case 'dev':
15-
shell.exec(`cross-env HOST=${host} PORT=${port} webpack-dev-server --hot --progress --inline --colors --content-base ./docroot`);
19+
shell.exec(`cross-env HOST=${host} PORT=${port} webpack-dev-server --hot --progress --no-info --inline --colors --content-base ./docroot`);
1620
break;
1721
case 'build':
1822
shell.exec(`cross-env rimraf docroot && webpack --progress --display-error-details`);

config/default.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"env": "default",
3-
"publicPath": "localhost:8080",
43
"host": "localhost",
54
"port": "8080",
65
"jsSourcePath": "src/js",
7-
"s3Deploy": false,
86
"s3": {
7+
"s3Deploy": false,
98
"bucket": "if-any",
109
"defaultCDNBase": "if-any"
1110
},
@@ -17,6 +16,10 @@
1716
"port": 8888
1817
}
1918
},
19+
"browserSync": {
20+
"active": true,
21+
"port": 3002
22+
},
2023
"html": [
2124
{
2225
"name": "homepage",

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "react-redux-boilerplate",
3-
"version": "0.9.56",
3+
"version": "0.9.58",
44
"description": "React Redux Boilerplate is a workflow boilerplate that make life easier for developers by providing a virtual development environment and production ready build process framework out of the box.",
55
"scripts": {
6-
"dev": "cross-env NODE_ENV=development webpack-dashboard -p 3300 -c red -t dashboard -- node bin/commands.js dev",
6+
"dev": "cross-env NODE_ENV=development DASHBOARD_PORT=9901 webpack-dashboard -p 9901 -c red -t dashboard -- node bin/commands.js dev",
77
"build": "cross-env NODE_ENV=production node bin/commands.js build",
88
"build:release": "cross-env NODE_ENV=release node bin/commands.js build",
99
"clean": "rimraf docroot",
@@ -93,8 +93,8 @@
9393
"react-router": "^4.2.0",
9494
"react-router-dom": "^4.2.2",
9595
"react-router-redux": "^4.0.8",
96-
"redux": "^3.7.2",
97-
"redux-actions": "^2.2.1",
96+
"redux": "^4.0.0",
97+
"redux-actions": "^2.3.0",
9898
"redux-saga": "^0.16.0",
9999
"reselect": "^3.0.1"
100100
},

webpack.config.dev.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import config from 'config';
22
import webpack from 'webpack';
33
import HtmlWebpackPlugin from 'html-webpack-plugin';
4-
import BrowserSyncPlugin from 'browser-sync-webpack-plugin';
54
import DashboardPlugin from 'webpack-dashboard/plugin';
65
import precss from 'precss';
76
import postcssCssnext from 'postcss-cssnext';
87

98
import webpackConfig, { JS_SOURCE } from './webpack.config.common';
109

11-
const PUBLIC_PATH = config.get('publicPath');
10+
const PUBLIC_PATH = `${config.get('host')}:${config.get('port')}`;
1211
const APP_ENTRY_POINT = `${JS_SOURCE}/router`;
1312

1413
const webpackDevOutput = {
@@ -43,7 +42,11 @@ const htmlPlugins = html.map((page) =>
4342
);
4443

4544
webpackConfig.plugins.push(
46-
new DashboardPlugin({ port: 3300 }),
45+
new DashboardPlugin({
46+
port: process.env.DASHBOARD_PORT,
47+
minified: false,
48+
gzip: false,
49+
}),
4750
new webpack.LoaderOptionsPlugin({
4851
debug: true
4952
}),
@@ -56,21 +59,29 @@ webpackConfig.plugins.push(
5659
NODE_ENV: JSON.stringify('development'),
5760
},
5861
}),
59-
new BrowserSyncPlugin({
60-
host: 'localhost',
61-
port: 3001,
62-
proxy: `http://localhost:${process.env.PORT}/`,
63-
64-
// Prevents BrowserSync from automatically opening up the app in your browser
65-
open: false,
66-
reloadDelay: 2500,
67-
}, {
68-
// Disable BrowserSync's browser reload/asset injections feature because
69-
// Webpack Dev Server handles this for us already
70-
reload: false,
71-
})
7262
);
7363

64+
// We turn off browserSync by default
65+
// Turn that on if you want to include this use case
66+
if(config.get('browserSync.active') === true) {
67+
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
68+
webpackConfig.plugins.push(
69+
new BrowserSyncPlugin({
70+
host: 'localhost',
71+
port: config.get('browserSync.port'),
72+
proxy: `http://localhost:${process.env.PORT}/`,
73+
74+
// Prevents BrowserSync from automatically opening up the app in your browser
75+
open: false,
76+
reloadDelay: 2500,
77+
}, {
78+
// Disable BrowserSync's browser reload/asset injections feature because
79+
// Webpack Dev Server handles this for us already
80+
reload: false,
81+
})
82+
);
83+
}
84+
7485
webpackConfig.module.rules = webpackConfig.module.rules.concat({
7586
test: /\.css$/,
7687
use: [

webpack.config.prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import webpackConfig, { JS_SOURCE } from './webpack.config.common';
1313
// CONSTANT DECLARATION
1414
// ----------------------------------------------------------
1515

16-
const S3_DEPLOY = config.get('s3Deploy') || 'false';
16+
const S3_DEPLOY = config.get('s3.s3Deploy') || 'false';
1717
const IS_S3_DEPLOY = String(S3_DEPLOY) === 'true';
1818

1919
const PUBLIC_PATH = IS_S3_DEPLOY ? process.env.AWS_CDN_URL : config.get('publicPath');

0 commit comments

Comments
 (0)