Create separate servers and configs for dev and prod

This commit is contained in:
Tanner Collin 2016-12-21 21:54:22 -07:00
parent 99443e25de
commit dd1e32ba0b
4 changed files with 75 additions and 11 deletions

View File

@ -3,7 +3,9 @@
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"scripts": { "scripts": {
"start": "node server.js", "dev": "node serverdev.js",
"build": "webpack --config ./webpack.production.config.js --progress --profile --colors",
"start": "npm run build && node server.js",
"lint": "eslint src" "lint": "eslint src"
}, },
"author": "Tanner Collin (http://github.com/tannercollin)", "author": "Tanner Collin (http://github.com/tannercollin)",
@ -18,6 +20,7 @@
"webpack-dev-server": "^1.8.2" "webpack-dev-server": "^1.8.2"
}, },
"dependencies": { "dependencies": {
"body-parser": "^1.15.2",
"freezer-js": "^0.6.0", "freezer-js": "^0.6.0",
"react": "^0.13.0", "react": "^0.13.0",
"react-router": "^0.13.3" "react-router": "^0.13.3"

View File

@ -1,15 +1,30 @@
var webpack = require('webpack'); const path = require('path');
var WebpackDevServer = require('webpack-dev-server'); const express = require('express');
var config = require('./webpack.config'); const bodyParser = require('body-parser');
new WebpackDevServer(webpack(config), { const app = express();
publicPath: config.output.publicPath,
hot: true, const host = 'http://localhost';
historyApiFallback: true const port = 3000;
}).listen(3000, 'localhost', function (err, result) {
app.use(bodyParser.urlencoded({ extended: false }));
app.use('/static', express.static(path.join(__dirname, 'dist')));
app.use('/assets', express.static(path.join(__dirname, 'assets')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.post('*', (req, res) => {
console.log("to: " + req.path);
console.log(Object.keys(req.body)[0]);
res.end();
});
app.listen(port, 'localhost', (err) => {
if (err) { if (err) {
console.log(err); console.log(err);
return;
} }
console.info('==> Listening on port %s. Open up %s:%s/ in your browser.', port, host, port);
console.log('Listening at localhost:3000');
}); });

16
serverdev.js Normal file
View File

@ -0,0 +1,16 @@
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
noInfo: true
}).listen(3000, 'localhost', function (err, result) {
if (err) {
console.log(err);
}
console.log('Listening at localhost:3000');
});

View File

@ -0,0 +1,30 @@
var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: 'source-map',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
}),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [{
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
}]
}
};