-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.watch.js
106 lines (94 loc) · 2.14 KB
/
rollup.watch.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const fs = require("fs");
const path = require('path');
const express = require("express");
const resolve = require('rollup-plugin-node-resolve');
const babel = require('rollup-plugin-babel');
const rollup = require("rollup");
const ts = require('rollup-plugin-typescript2');
const { terser } = require("rollup-plugin-terser");
const extensions = [
'.js',
'.ts',
];
// --- TS ---
const getPath = _path => path.resolve(__dirname, _path)
const tsPlugin = ts({
// - 导入本地ts配置 -
tsconfig: getPath('./tsconfig.json'),
extensions,
});
const watchOption = {
input: './src/index.ts',
output: {
file: './lib/eagle-eye.js',
format: 'umd',
name: "eagleEye",
},
plugins: [
resolve(extensions),
tsPlugin,
babel({
exclude: 'node_modules/**'
}),
terser(),
// uglify(),
],
watch: {
chokidar: true,
include: 'src/**',
exclude: "node_modules/**"
}
};
const watcher = rollup.watch(watchOption);
watcher.on('event', event => {
switch (event.code) {
case 'START':
console.log('Rebuilding...');
break;
case 'BUNDLE_START':
console.log('Bundling...');
break;
case 'BUNDLE_END':
console.log('Bundled!');
break;
case 'END':
console.log('Done!');
break;
case 'ERROR':
case 'FATAL':
console.error("Rollup error: ", event);
}
});
process.on('exit', () => {
// 停止监听
watcher.close();
});
const app = express();
app.use(express.static('./'))
// 设置允许跨域访问该服务
app.all('*', function (req, res, next) {
res.header("Access-Control-Allow-Origin", req.headers.origin);
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Credentials', true);
next();
});
app.use("/report", (req, res) => {
res.send({
code: 200,
result: 'success',
msg: 'success',
// serverOpenRecord: true,
})
});
app.use("/slow", (req, res) => {
setTimeout(() => {
res.send({
code: 200,
result: 'success',
msg: 'success',
})
}, 700)
});
const point = 3002;
console.log("+++++++++", "http://localhost:3002")
app.listen(point);