Skip to content

Commit

Permalink
Fixed dev server
Browse files Browse the repository at this point in the history
  • Loading branch information
yongjun21 committed Aug 22, 2016
1 parent f36f6cc commit fb011b3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
</head>
<body>
<div id="root"></div>
<script defer src="/bundle.js"></script>
<script>
window.googleMapsLoaded = false
window.googleOnLoadCallback = function () {
window.googleMapsLoaded = true
}
</script>
<script defer src="/bundle.js"></script>
</body>
</html>
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
"start": "if-env NODE_ENV=production && npm run start:prod || npm run start:dev",
"start:dev": "npm run build:dev && npm run start-server",
"start:prod": "npm run build:release && npm run start-server",
"webpack:dev": "webpack-dev-server --host 0.0.0.0 --port 9000 --progress --colors --hot --inline --config ./webpack.dev.config.js",
"start-server": "node server_dist/server.js",
"build:dev": "npm run clean && npm run build-server",
"build:release": "npm run clean && npm run build-server && npm run build-js",
"build-server": "babel server_src --out-dir server_dist",
"clean": "rm -rf server_dist",
"build-server": "babel server_src --out-dir server_dist",
"build-js": "webpack --progress --colors --config ./webpack.prod.config.js"
},
"contributors": [
Expand Down
12 changes: 6 additions & 6 deletions server_src/server.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import config from '../webpack.dev.config';

module.exports = function() {

export default function () {
let server = new WebpackDevServer(webpack(config), {
contentBase: './dist',
hot: true,
historyApiFallback: true,
proxy: {
'*': 'http://localhost:8080'
}
}).listen(9000, '0.0.0.0', function (err, result) {
},
stats: { colors: true }
});
server.listen(9000, '0.0.0.0', function (err, result) {
if (err) console.log(err);
console.log('Listening at 0.0.0.0:9000');
});

}
}
15 changes: 6 additions & 9 deletions server_src/server.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import app from './app.js';
import devServer from './server.dev';

const port = process.env.PORT || 8080;

const node_env = process.env.NODE_ENV|| 'development';

console.log('node env', node_env);

if (node_env === 'development') {

const wpBundle = require('./server.dev');
wpBundle();
const nodeEnv = process.env.NODE_ENV || 'development';
console.log('node env', nodeEnv);

if (nodeEnv === 'development') {
devServer();
}

app.listen(port);
console.log('Listening at: ' + port);
console.log('Listening at: ' + port);
13 changes: 5 additions & 8 deletions webpack.dev.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let autoprefixer = require('autoprefixer');
let Webpack = require('webpack');
var path = require('path');
var autoprefixer = require('autoprefixer');
var Webpack = require('webpack');

module.exports = {
entry: [
Expand All @@ -18,19 +19,15 @@ module.exports = {
}]
},
postcss: function () {
return [autoprefixer]
return [autoprefixer];
},
resolve: {
extensions: ['', '.js', '.jsx']
},
output: {
path: __dirname + '/dist',
path: path.join(__dirname, '/dist'),
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: './dist',
hot: true
},
plugins: [new Webpack.HotModuleReplacementPlugin()]
};

0 comments on commit fb011b3

Please sign in to comment.