-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
26 lines (23 loc) · 874 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const express = require('express');
const app = express();
const path = require('path');
const assetPath = path.join(__dirname, './client', 'index.html');
app.listen(3000, function () {
console.log('node:', process.env.NODE_ENV);
console.log('port: 3000');
});
if (process.env.NODE_ENV === 'production'){
const jsPath = path.resolve(__dirname) + '/dist';
app.use(express.static(jsPath));
} else {
const webpack = require('webpack');
const config = require('./webpack.config.dev.js');
const compiler = webpack(config);
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
app.use(webpackDevMiddleware(compiler, {noInfo: true, publicPath: config.output.publicPath}));
app.use(webpackHotMiddleware(compiler));
}
app.get('*', function(req, res) {
res.sendFile(assetPath);
});