2018-05-27 12:57:21 +02:00
|
|
|
/* eslint-disable no-console,global-require,import/no-extraneous-dependencies */
|
2018-05-25 15:00:27 +02:00
|
|
|
const express = require('express');
|
|
|
|
const path = require('path');
|
2016-03-15 23:42:10 +01:00
|
|
|
|
2018-05-27 14:35:37 +02:00
|
|
|
const PORT = 3001;
|
|
|
|
const DIST_DIR = path.join(__dirname, 'public');
|
2018-05-25 15:00:27 +02:00
|
|
|
|
2018-05-27 14:35:37 +02:00
|
|
|
const app = express();
|
2018-05-27 12:57:21 +02:00
|
|
|
|
2018-05-27 14:35:37 +02:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
2018-05-27 12:57:21 +02:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const webpackDevMiddleware = require('webpack-dev-middleware');
|
|
|
|
const webpackHotMiddleware = require('webpack-hot-middleware');
|
|
|
|
const config = require('./webpack.config.dev');
|
|
|
|
|
|
|
|
console.log('Compiling bundle... 👷🏽');
|
|
|
|
const compiler = webpack(config);
|
|
|
|
|
|
|
|
app.use(webpackDevMiddleware(compiler, {
|
2018-05-27 14:35:37 +02:00
|
|
|
publicPath: '/assets/scripts/',
|
2018-05-27 12:57:21 +02:00
|
|
|
stats: {
|
|
|
|
colors: true,
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2018-05-27 14:35:37 +02:00
|
|
|
app.use(webpackHotMiddleware(compiler));
|
2018-05-27 12:57:21 +02:00
|
|
|
}
|
|
|
|
|
2018-05-27 14:35:37 +02:00
|
|
|
app.use(express.static(DIST_DIR));
|
|
|
|
app.listen(PORT, (err) => {
|
2018-05-25 17:51:21 +02:00
|
|
|
if (err) {
|
|
|
|
console.log(err);
|
|
|
|
}
|
2018-05-27 12:57:21 +02:00
|
|
|
|
2018-05-27 18:13:29 +02:00
|
|
|
console.log(`Listening at http://localhost:${PORT} 👂`);
|
2018-05-25 17:51:21 +02:00
|
|
|
});
|