-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev-server.js
44 lines (33 loc) · 1.03 KB
/
dev-server.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
const express = require('express');
const webpack = require('webpack');
const app = express();
const config = require('./webpack.config.js');
const port = process.env.PORT || 5000;
const env = {
/**
* Webpack environment variables
*/
production: false,
};
const log = (message) =>
console.log(`[${new Date().toLocaleTimeString()}] ${message}`);
app.use(express.static('./dist'));
app.listen(port, () => {
console.log('====================================================');
console.log(`🚀 Development server running`);
console.log(`🌐 Open your browser at http://localhost:${port}`);
console.log('====================================================');
const compiler = webpack(config(env));
compiler.hooks.compile.tap('OnCompile', () => {
log('Compiling... 🛠️');
});
log('👀 Starting compiler in watch mode');
compiler.watch({}, (err, result) => {
if (result.hasErrors()) {
log('Compilation failed! ❌');
console.error(err);
} else {
log('Done! ✔️\n');
}
});
});