1 | import fs from 'fs';
|
2 | import path from 'path';
|
3 | import express from 'express';
|
4 | import webpack from 'webpack';
|
5 | import webpackMiddleware from 'webpack-dev-middleware';
|
6 | import config from './webpack.config.js';
|
7 |
|
8 | import examplesSSR from './src/examples-ssr.js';
|
9 |
|
10 | const port = 4114;
|
11 | const app = express();
|
12 |
|
13 | const compiler = webpack(config);
|
14 | const middleware = webpackMiddleware(compiler, {
|
15 | publicPath: config.output.publicPath,
|
16 | contentBase: 'src',
|
17 | stats: {
|
18 | colors: true,
|
19 | hash: false,
|
20 | timings: true,
|
21 | chunks: false,
|
22 | chunkModules: false,
|
23 | modules: false
|
24 | }
|
25 | });
|
26 |
|
27 | app.use(middleware);
|
28 | app.get('/', function(req, res) {
|
29 | res.write(fs.readFileSync(path.join(__dirname, 'index.html')));
|
30 | res.end();
|
31 | });
|
32 | app.get('/ssr/', function(req, res) {
|
33 | res.write(examplesSSR());
|
34 | res.end();
|
35 | });
|
36 |
|
37 | app.listen(port, '0.0.0.0', function(err) {
|
38 | if (err) {
|
39 | console.log(err);
|
40 | }
|
41 | console.info('==> Listening on port %s. Visit http://localhost:%s/ and http://localhost:%s/ssr in your browser.', port, port, port);
|
42 | });
|