Create separate servers and configs for dev and prod
This commit is contained in:
parent
99443e25de
commit
dd1e32ba0b
|
@ -3,7 +3,9 @@
|
|||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"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"
|
||||
},
|
||||
"author": "Tanner Collin (http://github.com/tannercollin)",
|
||||
|
@ -18,6 +20,7 @@
|
|||
"webpack-dev-server": "^1.8.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"body-parser": "^1.15.2",
|
||||
"freezer-js": "^0.6.0",
|
||||
"react": "^0.13.0",
|
||||
"react-router": "^0.13.3"
|
||||
|
|
35
server.js
35
server.js
|
@ -1,15 +1,30 @@
|
|||
var webpack = require('webpack');
|
||||
var WebpackDevServer = require('webpack-dev-server');
|
||||
var config = require('./webpack.config');
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
new WebpackDevServer(webpack(config), {
|
||||
publicPath: config.output.publicPath,
|
||||
hot: true,
|
||||
historyApiFallback: true
|
||||
}).listen(3000, 'localhost', function (err, result) {
|
||||
const app = express();
|
||||
|
||||
const host = 'http://localhost';
|
||||
const port = 3000;
|
||||
|
||||
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) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Listening at localhost:3000');
|
||||
console.info('==> Listening on port %s. Open up %s:%s/ in your browser.', port, host, port);
|
||||
});
|
||||
|
|
16
serverdev.js
Normal file
16
serverdev.js
Normal 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');
|
||||
});
|
30
webpack.production.config.js
Normal file
30
webpack.production.config.js
Normal 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')
|
||||
}]
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user