-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (45 loc) · 1.54 KB
/
index.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const config = require('./.config');
const express = require('express');
const fs = require('fs');
const webpack = require('webpack');
const compiler = webpack(require('./webpack.config'));
const app = express();
app.use(express.static('./public'));
app.use('/vanillatoasts', express.static(__dirname + '/node_modules/vanillatoasts'));
const routes = require('./src/routes');
for (const { path } of routes) {
app.get(path, function(req, res) {
fs.readFile('./public/index.html', (err, index) => {
if (err != null) {
return res.status(500).send(err.message);
}
res.send(index.toString('utf8'));
});
});
}
if (process.env.NODE_ENV === 'development') {
const port = config.port || 3000;
app.listen(port, () => {
console.log('Listening on port ' + port);
});
compiler.watch({}, (err, stats) => {
if (err) {
process.nextTick(() => { throw new Error('Error compiling bundle: ' + err.stack); });
}
if (stats.compilation.errors.length) {
process.nextTick(() => { throw new Error('Error compiling bundle: ' + stats.compilation.errors[0].stack); });
}
console.log('Webpack compiled successfully');
});
} else {
compiler.run((err, stats) => {
if (err) {
process.nextTick(() => { throw new Error('Error compiling bundle: ' + err.stack); });
}
if (stats.compilation.errors.length) {
process.nextTick(() => { throw new Error('Error compiling bundle: ' + stats.compilation.errors[0].stack); });
}
console.log('Webpack compiled successfully');
});
}