forked from b3008/executable_HTML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
myLiveServer.js
32 lines (26 loc) · 1.32 KB
/
myLiveServer.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
var liveServer = require("live-server");
var childProcess = require('child_process').spawn;
var params = {
port: 8080, // Set the server port. Defaults to 8080.
host: "0.0.0.0", // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP.
// root: "/public", // Set root directory that's being served. Defaults to cwd.
open: false, // When false, it won't load your browser by default.
ignore: '/dist/', // comma-separated string for paths to ignore
file: "index.html", // When set, serve this file (server root relative) for every 404 (useful for single-page applications)
wait: 1000, // Waits for all changes, before reloading. Defaults to 0 sec.
mount: [['/components', './node_modules']], // Mount a directory to a route.
logLevel: 2, // 0 = errors only, 1 = some, 2 = lots
middleware: [function (req, res, next) {
//code here does not seem to execute
next();
}] // Takes an array of Connect-compatible middleware that are injected into the server middleware stack
};
liveServer.start(params);
liveServer.watcher.on('change', function (e) {
if (e.indexOf('/dist/') == -1) {
console.log('executing: npm run build');
childProcess(`cd ${__dirname}; npm run build`).on('error', function (err) {
console.log('ouch: ' + err);
});
}
})