Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

监控不到以版本号命名的文件夹下文件的变化 #41

Open
ufologist opened this issue Apr 24, 2017 · 0 comments
Open

监控不到以版本号命名的文件夹下文件的变化 #41

ufologist opened this issue Apr 24, 2017 · 0 comments

Comments

@ufologist
Copy link
Contributor

如果文件夹以版本号来命名, 例如文件夹名字为: 1.0.0, 会造成 puer 不去监听该文件夹下文件发生的变化, 导致不会自动刷新页面.

原因是 puer 判断了文件的后缀, 只针对特点类型的 fileType to watch, 默认是 'js|css|html|xhtml'

具体实现代码如下

// puer/lib/connect-puer.js
// filename: E:\xxx\test\1.0.0
//      ext: .0
matched = /\.(\w+)$/.exec(filename);
if (matched) {
    ext = matched[1];
    if (filetype.indexOf(ext) === -1) {
        console.log('ignore filetype', filename)
    }
    return filetype.indexOf(ext) === -1;
} else {
    return false;
}

例如文件夹的名字为 1.0.0 那么这里得到的后缀是 .0, 被认为不在监听的文件类型中, 造成这个文件夹下的所有文件的变化都不会被监听了

filename E:\xxx\test\1.0.0
ignore filetype E:\xxx\test\1.0.0

filename E:\xxx\test\index.html

filename E:\xxx\test\index.js

filename E:\xxx\test\node_modules
ignore ignored E:\xxx\test\node_modules

知道原因后, 我们就可以机智地绕过这个问题了, 但实属无奈之举啊, 如果版本号很多就麻烦了, 例如: 1.0.1 1.0.N, 那岂不是要将所有的数字都放到 fileType 配置项中...

puer -f "js|css|html|xhtml|0"

filename E:\xxx\test\1.0.0

filename E:\xxx\test\index.html

filename E:\xxx\test\index.js

filename E:\xxx\test\node_modules
ignore ignored E:\xxx\test\node_modules

filename E:\xxx\test\1.0.0\index.css

PS:

browser-sync 没有这个问题, 他也是使用的 chokidar 来监听文件的变化, 只不过他是直接将 glob 传给 chokidar 去处理, 而非通过文件类型来判断.

browser-sync start --server --files "**/*.html, **/*.css"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant