Created
February 2, 2016 17:47
-
-
Save cmcewen/96855ae470eac6bd51a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const Express = require('express'); | |
const webpack = require('webpack'); | |
const userConfig = require('./user-config'); | |
const path = require('path'); | |
const root = path.resolve(__dirname, '../../..'); | |
const sourceDir = path.resolve(root, './src'); | |
const config = require('./merge-configs')(userConfig(root, sourceDir)); | |
const webpackConfig = config.webpack.config; | |
const compiler = webpack(webpackConfig); | |
const host = config.server.host || 'localhost'; | |
const port = parseInt(config.server.port, 10) + 1 || 3001; | |
const serverOptions = { | |
contentBase: 'http://' + host + ':' + port, | |
quiet: true, | |
noInfo: true, | |
hot: true, | |
inline: true, | |
lazy: false, | |
publicPath: webpackConfig.output.publicPath, | |
headers: { 'Access-Control-Allow-Origin': '*' }, | |
stats: { colors: true } | |
}; | |
const app = new Express(); | |
app.use(require('webpack-dev-middleware')(compiler, serverOptions)); | |
app.use(require('webpack-hot-middleware')(compiler)); | |
app.listen(port, function onAppListening(err) { | |
if (err) { | |
console.error(err); | |
} else { | |
console.info('==> 🚧 Webpack development server listening on port %s', port); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment