Skip to content

Commit 9512e8b

Browse files
committed
Add build script & prod server & clean code.
- Add build script & prod server. - clean code on webpack settings.
1 parent 357d9ed commit 9512e8b

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "1.0.0-alpha",
44
"description": "React BoilerPlate with react bootstrap",
55
"scripts": {
6-
"start": "webpack-dev-server --port 3001 --progress --colors",
6+
"start": "webpack-dev-server --port 3334 --progress --colors",
77
"prod": "webpack -p --config webpack.config.prod.js --progress --colors",
8+
"start:prod": "node scripts/startProduct.js --port 5000",
89
"test": "cross-env NODE_ENV=test mocha --recursive --compilers js:babel-register --require ./test/setup.js",
910
"test:watch": "npm test -- --watch"
1011
},
@@ -54,6 +55,7 @@
5455
"react-addons-test-utils": "^0.14.7",
5556
"style-loader": "^0.13.2",
5657
"webpack": "^2.2.1",
57-
"webpack-dev-server": "^2.3.0"
58+
"webpack-dev-server": "^2.3.0",
59+
"yargs": "^7.0.1"
5860
}
5961
}

scripts/startProduct.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const express = require('express');
2+
const path = require('path');
3+
const argv = require('yargs').argv;
4+
console.log("argv", argv);
5+
6+
const app = new express();
7+
const port = argv.port || 3334;
8+
9+
10+
app.use('/', express.static(path.join(__dirname, '../build')));
11+
12+
app.get("*", function(req, res) {
13+
res.sendFile(path.join(__dirname, '../build/index.html'))
14+
});
15+
16+
app.listen(port, function(error) {
17+
if (error) {
18+
console.error(error)
19+
} else {
20+
console.info("==> 🌎 Listening on port %s. Open up http://localhost:%s/ in your browser.", port, port)
21+
}
22+
});

webpack.config.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var ExtractTextPlugin = require("extract-text-webpack-plugin");
44
var webpack = require('webpack');
55
module.exports = {
66
// devtool: 'inline-source-map',
7-
devtool: 'cheap-source-map',
7+
devtool: 'cheap-module-eval-source-map',
88
entry: {
99
app: './src/index'
1010
},
@@ -15,9 +15,7 @@ module.exports = {
1515
},
1616
devServer: {
1717
hot: true,
18-
inline: true,
19-
quiet: false,
20-
noInfo: true
18+
inline: true
2119
},
2220
plugins: [
2321
new webpack.HotModuleReplacementPlugin(),

webpack.config.prod.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ module.exports = {
1212
filename: 'bundle.js',
1313
publicPath: '/'
1414
},
15-
devServer: {
16-
hot: true,
17-
inline: true,
18-
quiet: false,
19-
noInfo: true
20-
},
2115
plugins: [
2216
new webpack.DefinePlugin({
2317
'process.env': {
@@ -27,7 +21,8 @@ module.exports = {
2721
new ExtractTextPlugin("bundle.css"),
2822
new CopyWebpackPlugin([
2923
{
30-
from: 'src/public/**/*'
24+
context: "src/public",
25+
from: '**/*'
3126
}
3227
])
3328
],

0 commit comments

Comments
 (0)