1 | let fs = require('fs-extra')
|
2 | let chokidar = require('chokidar')
|
3 | let Path = require('path')
|
4 | let utils = require('../utils/utils')
|
5 | let projectConfig = utils.getProjectConfig()
|
6 | let log = utils.log
|
7 | let jsCompiler = require('./compiler/compile-js')
|
8 | let cssCompiler = require('./compiler/compile-css')
|
9 |
|
10 | log.tag('监听文件变动中')
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function jsAnylase(path){
|
26 |
|
27 | return [path]
|
28 | }
|
29 |
|
30 |
|
31 | let watcher = chokidar.watch(utils.getSrcPath())
|
32 | watcher.on('change', path => {
|
33 | let ext = Path.extname(path)
|
34 | if (ext === projectConfig.css.ext) {
|
35 | cssCompiler(path)
|
36 |
|
37 |
|
38 |
|
39 | }
|
40 | else if (ext === projectConfig.js.ext) {
|
41 |
|
42 | jsCompiler.compiler(path)
|
43 | jsCompiler.clearTrace()
|
44 | }
|
45 | else {
|
46 |
|
47 | let destPath = utils.getOutputFile(path)
|
48 | fs.copySync(path,destPath)
|
49 | log.tag('复制文件',`${destPath}`)
|
50 | }
|
51 | }) |
\ | No newline at end of file |