mirror of
https://github.com/PrismarineJS/prismarine-web-client.git
synced 2024-11-24 16:47:52 -05:00
c8e3ffd019
* introduce prod/dev build https://webpack.js.org/guides/production/ * use it properly with express https://webpack.js.org/guides/development/#using-webpack-dev-middleware to provide a fast npm start (5 second)
32 lines
925 B
JavaScript
32 lines
925 B
JavaScript
#!/usr/bin/env node
|
|
|
|
const express = require('express')
|
|
const netApi = require('net-browserify')
|
|
const compression = require('compression')
|
|
const path = require('path')
|
|
|
|
// Create our app
|
|
const app = express()
|
|
|
|
app.use(compression())
|
|
app.use(netApi({ allowOrigin: '*' }))
|
|
if (process.argv[3] === 'dev') {
|
|
// https://webpack.js.org/guides/development/#using-webpack-dev-middleware
|
|
const webpackDevMiddleware = require('webpack-dev-middleware')
|
|
const config = require('./webpack.dev.js')
|
|
const webpack = require('webpack')
|
|
const compiler = webpack(config)
|
|
|
|
app.use(
|
|
webpackDevMiddleware(compiler, {
|
|
publicPath: config.output.publicPath
|
|
})
|
|
)
|
|
} else {
|
|
app.use(express.static(path.join(__dirname, './public')))
|
|
}
|
|
|
|
// Start the server
|
|
const server = app.listen(process.argv[2] === undefined ? 8080 : process.argv[2], function () {
|
|
console.log('Server listening on port ' + server.address().port)
|
|
})
|