-
Notifications
You must be signed in to change notification settings - Fork 15
/
server.js
52 lines (42 loc) · 1.2 KB
/
server.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
52
/**
* Copyright (c) 2017 Alibaba Group Holding Limited
* @author Simon <[email protected]>
*/
const express = require('express')
const webpack = require('webpack')
const path = require('path')
const comp = require('compression')
// create normal express app
const app = express()
// create a webpack conpiter
const config = require('./webpack.config')
const compiler = webpack(config)
// set dev_option
var devOption = {
noInfo: true,
publicPath: config.output.publicPath, // 静态文件位置
stats: 'minimal',
historyApiFallback: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
}
app.use(comp())
app.use(require('webpack-dev-middleware')(compiler, devOption))
app.use('/assets', express.static(path.join(__dirname, '/assets')))
app.get('/favicon.ico', (req, res) => {
res.end('')
})
// compit jade & route '/'to index.html
app.get('/html/:demoName', (req, res) => {
console.log('visiting demo:', req.params.demoName)
res.sendFile(path.join(__dirname, `/demo/${req.params.demoName}.html`))
})
// listen
app.listen(3112, '0.0.0.0', err => {
if (err) {
console.log(err)
} else {
console.log('Listening @ http://localhost:3112')
}
})