-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
51 lines (42 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* A demo for http://ant.design/
*
* v0.1.0 - 2015-12-15
* @author Carrotzpc
*/
'use strict';
const koa = require('koa')
const logger = require('koa-logger')
const Router = require('koa-router')
const render = require('koa-ejs')
const serve = require('koa-static')
const webpack = require('webpack')
const app = koa()
// middleware
app.use(logger())
// webpack
const webpackDevMiddleware = require('koa-webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const webpackConfig = require('./webpack.config')
const compiler = webpack(webpackConfig)
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: webpackConfig.output.publicPath }))
app.use(function* (next) {
yield webpackHotMiddleware(compiler).bind(null, this.req, this.res)
yield next
})
// serve files from ./dist
app.use(serve(__dirname + '/dist'))
// views
render(app, {
root: __dirname,
layout: false,
viewExt: 'html',
debug: true,
cache: false
})
app.use(function *() {
yield this.render('index', { title: '首页', body: '<h1>ant-koa-demo</h1>' });
})
// listen
app.listen(3001)
console.log('listening on port 3001')