require("babel-register")
const express = require("express")
const webpack = require("webpack")
const webpackConfig = require("./webpack.config")
const app = express()
// webpack
var compiler = webpack(webpackConfig);
// webpack-dev-server
var devMiddleware = require("webpack-dev-middleware")(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: {
colors: true,
chunks: false
}
});
app.use(devMiddleware)
//
app.get("/:viewname?", function(req, res, next) {
var viewname = req.params.viewname ? req.params.viewname + ".html" : "index.html";
var filepath = path.join(compiler.outputPath, viewname);
// webpackoutputFileSystem
compiler.outputFileSystem.readFile(filepath, function(err, result) {
if (err) {
// something error
return next(err);
}
console.log(22222, result)
res.set("content-type", "text/html");
res.send(result);
res.end();
});
});
module.exports = app.listen(3000)