forked from didi/mand-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev-server.rollup.js
64 lines (52 loc) · 1.35 KB
/
dev-server.rollup.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
53
54
55
56
57
58
59
60
61
62
63
64
const rollup = require('rollup')
const path = require('path')
const { rollupPlugin, DEV_OUTPUT_DIR, PROJECT_DIR } = require('./rollup-plugin-config')
// express
const livereload = require('livereload')
const express = require('express')
const history = require('connect-history-api-fallback')
// const opn = require('opn')
const port = 4000
const inputOptions = {
input: path.resolve(PROJECT_DIR, 'examples/main.indemand.js'),
plugins: rollupPlugin,
}
const outputCommonjsOptions = {
file: path.resolve(DEV_OUTPUT_DIR, 'mand-mobile-dev.js'),
format: 'umd',
}
function watch() {
const watchOptions = Object.assign(inputOptions, {
output: outputCommonjsOptions,
})
const watcher = rollup.watch(watchOptions)
watcher.on('event', e => {
console.info(e)
if (e.code === 'END') {
console.info('resource rebuild')
}
if (e.code === 'ERROR') {
console.info(e)
}
})
}
function serve(path) {
return express.static(path, {})
}
function runServer() {
// rollup buildwatch
watch()
// livereload
const lrserver = livereload.createServer()
lrserver.watch(path.join(process.cwd(), 'output'))
// static resource server
const app = express()
app.use(history({
verbose: true
}))
app.use('/', serve(DEV_OUTPUT_DIR))
app.listen(port, function() {
console.log('> Starting dev server...')
})
}
runServer()