No Description

server.ts 893B

123456789101112131415161718192021222324252627
  1. import * as fs from "fs";
  2. import * as express from "express";
  3. import * as webpackMiddleware from "webpack-dev-middleware";
  4. import * as webpackHotMiddleware from "webpack-hot-middleware";
  5. import * as webpack from "webpack";
  6. import * as webpackConfig from "../webpack.config.demo.dev";
  7. const packageJson = require("../package.json");
  8. const webpackCompiler = webpack(webpackConfig as any);
  9. const port = 4000;
  10. require.extensions[".html"] = (module, filename) => {
  11. module.exports = fs.readFileSync(filename, "utf8");
  12. };
  13. const app = express();
  14. app.use(webpackMiddleware(webpackCompiler));
  15. app.use(webpackHotMiddleware(webpackCompiler));
  16. app.use((req, res) => res.status(200).send(require("./index.html")));
  17. app.listen(port, "0.0.0.0", () => {
  18. const demoUrl = `http://localhost:${port}/`;
  19. // tslint:disable-next-line
  20. console.log(`${packageJson.name} running at ${demoUrl}`);
  21. });