hyperboria/rules/nodejs/webpack.dynamic.server.js
the-superpirate 8472f27ec5 No description
GitOrigin-RevId: ddf02e70d2827c048db49b687ebbcdcc67807ca6
2021-01-04 18:12:22 +03:00

23 lines
740 B
JavaScript

const config = require('./{config_path}')
const webpackConfig = require('./{webpack_config_path}')
const webpack = require('webpack')
const express = require('express')
const app = express()
const path = require('path')
const outputPath = path.join(process.cwd(), '{static_path}')
webpackConfig.output.path = outputPath
webpack(webpackConfig, (err, stats) => { // Stats Object
if (err || stats.hasErrors()) {
console.error(err || stats)
}
app.use(express.static(outputPath))
app.get('/', (req, res) => {
res.sendFile('./index.html', { root: outputPath })
})
app.listen(config.application.port, config.application.host, () => {
console.log(`Dynamic server is listening on port: ${config.application.port}`)
})
})