-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
27 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Router } from 'express'; | ||
import webpack from 'webpack'; | ||
import webpackDevMiddleware from 'webpack-dev-middleware'; | ||
import webpackHotMiddleware from 'webpack-hot-middleware'; | ||
import baseConfig from './webpack.config'; | ||
import loadConfig from './config'; | ||
import getIndexHtml from './index.html'; | ||
import getIframeHtml from './iframe.html'; | ||
import { getHeadHtml } from './utils'; | ||
|
||
export default function (configDir) { | ||
// Build the webpack configuration using the `baseConfig` | ||
// custom `.babelrc` file and `webpack.config.js` files | ||
const config = loadConfig('DEVELOPMENT', baseConfig, configDir); | ||
const compiler = webpack(config); | ||
const devMiddlewareOptions = { | ||
noInfo: true, | ||
publicPath: config.output.publicPath, | ||
}; | ||
|
||
const router = new Router(); | ||
router.use(webpackDevMiddleware(compiler, devMiddlewareOptions)); | ||
router.use(webpackHotMiddleware(compiler)); | ||
|
||
router.get('/', function (req, res) { | ||
res.send(getIndexHtml()); | ||
}); | ||
|
||
const headHtml = getHeadHtml(configDir); | ||
router.get('/iframe.html', function (req, res) { | ||
res.send(getIframeHtml(headHtml)); | ||
}); | ||
|
||
return router; | ||
} |