Last active
February 1, 2018 15:50
-
-
Save bryzettler/38f536452403ff1e52a7167f9e32c016 to your computer and use it in GitHub Desktop.
This file contains 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
const Bundler = requrie('parcel-bundler'); | |
const express = require('express'); | |
const chalk = require('chalk'); | |
const httpProxyMiddleware = require('http-proxy-middleware'); | |
const openBrowser = require('react-dev-utils/openBrowser'); | |
const devServer = express(); | |
// setup parcel | |
const bundle = new Bundler(paths.appHtml, { | |
outDir: paths.appBuild, | |
// no cache on dev | |
cache: false, | |
}); | |
const addProxy = () => { | |
const proxy = require(paths.appPackageJson).proxy; | |
if (proxy) { | |
devServer.use( | |
'/api'; | |
httpProxyMiddleware({ | |
target: proxy, | |
changeOrigin: true, | |
}) | |
); | |
} | |
}; | |
const runDevServer = (host, port, protocol) => { | |
addProxy(); | |
// add parcel in as middleware | |
devServer.use(bundler.middleware()); | |
devServer.listen(port, (err, result) => { | |
if (err) return console.log(err); | |
console.log('The app is running at:'); | |
console.log(' ' + chalk.cyan(protocol + '://' + host + ':' + port + '/')); | |
console.log('Note that the development build is not optimized.'); | |
console.log('To create a production build, use ' + chalk.cyan('npm run build') + '.'); | |
console.log(chalk.cyan('Starting the development server...')); | |
openBrowser(protocol + '://' + host + ':' + port + '/'); | |
}); | |
}; | |
const run = (port) => { | |
var protocol = process.env.HTTPS === 'true' ? "https" : "http"; | |
var host = process.env.HOST || 'localhost'; | |
runDevServer(host, port, protocol); | |
} | |
run(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment