From 5b3a976fd33a258b4140dc8c53c6a0b5ff6198cc Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 24 Apr 2023 09:33:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A0=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E5=8D=A0=E7=94=A8=E5=AF=BC=E8=87=B4=E7=9A=84=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E9=87=8D=E5=A4=8D=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/dev.js | 96 +++++++++++++++++++++++++++------------------------- package.json | 2 +- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/lib/dev.js b/lib/dev.js index 65b004e..fb7332e 100644 --- a/lib/dev.js +++ b/lib/dev.js @@ -295,60 +295,62 @@ export default async function createServer(root = '', conf = {}) { PORT, DEPLOY_PATH ) - }) + chokidar + .watch([SOURCE_DIR, PUBLIC_DIR, join(root, './index.html')]) + .on('all', (act, filePath) => { + if (ready) { + let file = filePath.slice(SOURCE_DIR.length) - chokidar - .watch([SOURCE_DIR, PUBLIC_DIR, join(root, './index.html')]) - .on('all', (act, filePath) => { - if (ready) { - let file = filePath.slice(SOURCE_DIR.length) + if (act === 'add' || act === 'change') { + let ext = file.slice(file.lastIndexOf('.') + 1) - if (act === 'add' || act === 'change') { - let ext = file.slice(file.lastIndexOf('.') + 1) + switch (ext) { + case 'css': + case 'scss': + { + let content = fs.cat(filePath).toString() + ws.send({ + action: 'render', + data: { path: file.replace(/\\/g, '/'), content } + }) + } + break - switch (ext) { - case 'css': - case 'scss': - { - let content = fs.cat(filePath).toString() - ws.send({ - action: 'render', - data: { path: file.replace(/\\/g, '/'), content } - }) - } - break + case 'vue': + { + let content = compileVue(filePath, conf.imports, { + IS_MPA, + currentPage, + SOURCE_DIR, + CACHE, + DEPLOY_PATH + }) + let tmp = CACHE[filePath] + if (tmp.changed) { + ws.send({ action: 'reload' }) + } else { + ws.send({ + action: 'render', + data: { + path: file.replace(/\\/g, '/'), + content: tmp.css + } + }) + } + } + break - case 'vue': - { - let content = compileVue(filePath, conf.imports, { - IS_MPA, - currentPage, - SOURCE_DIR, - CACHE, - DEPLOY_PATH - }) - let tmp = CACHE[filePath] - if (tmp.changed) { + default: ws.send({ action: 'reload' }) - } else { - ws.send({ - action: 'render', - data: { path: file.replace(/\\/g, '/'), content: tmp.css } - }) - } + break } - break - - default: + } else if (act === 'unlink' || act === 'unlinkDir') { ws.send({ action: 'reload' }) - break + } } - } else if (act === 'unlink' || act === 'unlinkDir') { - ws.send({ action: 'reload' }) - } - } - }) - .on('ready', () => { - ready = true + }) + .on('ready', () => { + ready = true + }) }) } diff --git a/package.json b/package.json index 65d4af7..303f8ea 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fite", "type": "module", - "version": "0.6.1", + "version": "0.6.2", "bin": { "fite": "index.js" },