forked from mgechev/angular-seed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_change_tools.ts
More file actions
48 lines (44 loc) · 1.15 KB
/
Copy pathcode_change_tools.ts
File metadata and controls
48 lines (44 loc) · 1.15 KB
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
import * as express from 'express';
import * as connectLivereload from 'connect-livereload';
import {ENABLE_HOT_LOADING, LIVE_RELOAD_PORT, HOT_LOADER_PORT, APP_SRC, APP_BASE, PROJECT_ROOT} from '../config';
import * as ng2HotLoader from 'angular2-hot-loader';
import * as tinylrFn from 'tiny-lr';
import {join} from 'path';
let tinylr = tinylrFn();
let listen = () => {
if (ENABLE_HOT_LOADING) {
return ng2HotLoader.listen({
port: HOT_LOADER_PORT,
processPath: file => {
return file.replace(join(PROJECT_ROOT, APP_SRC), join('dist', 'dev'));
}
});
} else {
return tinylr.listen(LIVE_RELOAD_PORT);
}
};
let changed = files => {
if (!(files instanceof Array)) {
files = [files];
}
if (ENABLE_HOT_LOADING) {
ng2HotLoader.onChange(files);
} else {
tinylr.changed({
body: { files }
});
}
};
let tinylrMiddleware = connectLivereload({ port: LIVE_RELOAD_PORT });
let middleware = [
APP_BASE,
(req, res, next) => {
if (ENABLE_HOT_LOADING) {
next();
} else {
tinylrMiddleware(req, res, next);
}
},
express.static(process.cwd())
];
export { listen, changed, middleware };