Skip to content

Commit 98ff14a

Browse files
committed
重写compile,加速watch时的编译速度
1 parent ddb8ebc commit 98ff14a

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ require('./lib/util.js');
5151
//require cli.js overwrite fis-cli.js
5252
require('./cli.js');
5353

54+
feather.compile = require('./lib/compile.js');
55+
5456
//lookup查找规则 如果是非/|.开头的文件,查找时,优先按照相对路径处理,找不到,按照相对于根目录处理
5557
//以便统一所有情况
5658
var lookup = feather.project.lookup;

lib/compile.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ function storeWatchCache(file){
2525
watchCache[file.realpath] = tempFile;
2626
}
2727

28+
function checkWathFileExpires(wFile, file){
29+
if(wFile.mtime.getTime() != file.getMtime().getTime()){
30+
return true;
31+
}
32+
33+
var deps = wFile.cache.deps;
34+
35+
for(var dep in deps){
36+
var d = fis.file(dep);
37+
38+
if(d.getMtime().getTime() > deps[dep]){
39+
return true;
40+
}
41+
}
42+
43+
return false;
44+
}
45+
2846
/**f
2947
* 编译相关函数入口, 输入为 文件对象,没有输出,直接修改文件对象内容。
3048
*
@@ -55,11 +73,11 @@ var exports = module.exports = function(file, memoryStore) {
5573
if (memoryCache[file.realpath]) {
5674
revertFromMemory(file, memoryCache[file.realpath]);
5775
return file;
58-
} else {
76+
} else if(exports.settings.watch) {
5977
var watchCacheFile = watchCache[file.realpath];
6078

6179
if (watchCacheFile) {
62-
if (watchCacheFile.mtime.getTime() == file.getMtime().getTime()) {
80+
if (!checkWathFileExpires(watchCacheFile, file)) {
6381
revertFromMemory(file, watchCacheFile);
6482
fis.emit('compile:start', file);
6583
file.compiled = true;

lib/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ _.isRemoteUrl = function(path){
7575

7676
_.delAsync = function(path){
7777
var cp = require('child_process');
78-
var child = cp.fork(__dirname + '/asyncDel.js');//每个请求都单独生成一个新的子进程
78+
var child = cp.fork(__dirname + '/delAsync.js');//每个请求都单独生成一个新的子进程
7979
child.send(path);
8080
};

0 commit comments

Comments
 (0)