File tree Expand file tree Collapse file tree 1 file changed +31
-7
lines changed Expand file tree Collapse file tree 1 file changed +31
-7
lines changed Original file line number Diff line number Diff line change 1
1
"use strict" ;
2
- const plutils = require ( './utilities' ) ;
3
2
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' ) ;
9
4
10
5
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
+
12
36
} ;
13
37
14
38
module . exports = serve ;
You can’t perform that action at this time.
0 commit comments