Skip to content

Commit c198aad

Browse files
committed
first draft of @raphaelokon's custom live-server
part of #609
1 parent 58d40dd commit c198aad

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

core/lib/serve.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
"use strict";
2-
const plutils = require('./utilities');
32
const path = require('path');
4-
const process = require('process');
5-
const assetCopier = require('./asset_copy');
6-
7-
let copy = require('recursive-copy'); // eslint-disable-line
8-
let chokidar = require('chokidar'); // eslint-disable-line
3+
const liveServer = require('live-server');
94

105
const serve = (patternlab) => {
11-
console.log('serve');
6+
7+
// our default liveserver config
8+
const defaults = {
9+
root: patternlab.config.paths.public.root,
10+
open: true,
11+
ignore: path.join(path.resolve(patternlab.config.paths.public.root)),
12+
file: 'index.html',
13+
logLevel: 0 // errors only
14+
};
15+
16+
// allow for overrides should they exist inside patternlab-config.json
17+
const liveServerConfig = Object.assign({}, defaults, patternlab.config.serverOptions);
18+
19+
// watch for asset changes, and reload appropriately
20+
patternlab.events.on('patternlab-asset-change', (data) => {
21+
if (data.file.indexOf('css') > -1) {
22+
liveServer.refreshCSS();
23+
} else {
24+
liveServer.reload();
25+
}
26+
});
27+
28+
//watch for pattern changes, and reload
29+
patternlab.events.on('patternlab-pattern-change', () => {
30+
liveServer.reload();
31+
});
32+
33+
//start!
34+
liveServer.start(liveServerConfig);
35+
1236
};
1337

1438
module.exports = serve;

0 commit comments

Comments
 (0)