Skip to content

Commit

Permalink
make webpack run with local server
Browse files Browse the repository at this point in the history
  • Loading branch information
segunolalive committed Sep 6, 2017
1 parent 7681218 commit 18cb961
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -7,6 +7,7 @@
"serve": "babel-node server/bin/www.js",
"start:client": "webpack-dev-server --hot --config ./webpack.dev.config.js",
"start:dev": "nodemon server/bin/www --exec babel-node",
"start:server": "nodemon server/server --exec babel-node",
"test:travis": "cross-env NODE_ENV=test nyc mocha -t 5000 --compilers js:babel-register server/test/**/*.spec.js",
"pretest": "sequelize db:migrate:undo:all --env test && sequelize db:migrate --env test && cross-env NODE_ENV=test npm run seed:tables",
"test": "cross-env NODE_ENV=test npm run seed:join && npm run test:travis",
Expand Down
25 changes: 13 additions & 12 deletions server/app.js
Expand Up @@ -22,17 +22,18 @@ app.use((req, res, next) => {
next();
});

if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'client/static')));
routes(app);
app.get('/bundle.js', (req, res) => res.sendFile(
path.join(path.dirname(__dirname), 'client/bundle.js')
));
app.get('/*', (req, res) => res.sendFile(
path.join(path.dirname(__dirname), 'client/index.html'))
);
} else {
routes(app);
}

app.use(express.static(path.join(__dirname, 'client/static')));

routes(app);

app.get('/bundle.js', (req, res) => res.sendFile(
path.join(path.dirname(__dirname), 'client/bundle.js')
));

app.get('/*', (req, res) => res.sendFile(
path.join(path.dirname(__dirname), 'client/index.html'))
);


export default app;
6 changes: 5 additions & 1 deletion webpack.dev.config.js
Expand Up @@ -11,7 +11,11 @@ const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({

module.exports = {
devtool: 'inline-source-map',
entry: './client/index.js',
entry: [
// reload the page if hot module reloading fails.
'webpack-hot-middleware/client?reload=true',
path.resolve(__dirname, 'client/index.js')
],
output: {
filename: 'bundle.js',
publicPath: '/',
Expand Down

0 comments on commit 18cb961

Please sign in to comment.