Created
December 9, 2015 19:04
-
-
Save leandrooriente/367ba8a01e784742e0ce 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
'use strict'; | |
let webpack = require('webpack'); | |
let webpackDevMiddleware = require('webpack-dev-middleware'); | |
let colors = require('colors'); | |
let path = require('path'); | |
let proxy = require('proxy-middleware'); | |
let url = require('url'); | |
let config; | |
let app = new require('express')(); | |
let port = 3000; | |
if (process.env.NODE_ENV === 'production') { | |
config = require('./webpack/webpack.production.config'); | |
console.log(colors.green('PRODUCTION - Environment')); | |
} else { | |
config = require('./webpack/webpack.development.config'); | |
console.log(colors.green('DEVELOPMENT - Environment')); | |
} | |
let compiler = webpack(config) | |
if (process.env.NODE_ENV !== 'production') { | |
app.use(require('webpack-hot-middleware')(compiler)); | |
app.use('/api', proxy(url.parse('http://localhost:8080/api'))); | |
} | |
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: config.output.publicPath })); | |
app.get('*', function(req, res) { | |
res.sendFile(path.join(__dirname, 'index.html')); | |
}); | |
app.listen(port, function(error) { | |
if (error) { | |
console.error(error); | |
} else { | |
console.info('==> 🌎 Listening on port %s. Open up http://localhost:%s/ in your browser.', port, port); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment