Chokidar 未获取 docker 容器内的文件更改
Chokidar isn't picking up file changes inside docker container
我正在使用 docker 用于 mac 版本 1.12.0-rc2 的反应项目。我的工作流程是这样的:
src/
OS X 上的文件夹已安装到容器
- 当开发人员修改
src/
中的文件时,它会转换为 ES5 并放置在 public/
中(这有效)。
- 当文件在
public/
中更改时,另一个观察者触发热重新加载(在我的本地主机上工作,但在容器中不工作)。
这是第 3 步中我的计步器代码:
// root = "/src"
const watcher = chokidar.watch(root, {
usePolling: true,
awaitWriteFinish: {
pollInterval: 100,
stabilityThreshold: 250
},
ignored: /\.(git|gz|map)|node_modules|jspm_packages|src/,
ignoreInitial: true,
persistent: true
})
.on("change", function fileWatcher(filename) {
const modulePath = filename.replace(`${root}/`, "");
wss.clients.forEach(function sendFileChange(client) {
send("filechange", modulePath, client);
});
if (cache[filename]) {
wss.clients.forEach(function sendCacheFlush(client) {
send("cacheflush", filename, client);
});
delete cache[filename];
}
});
还有我的 docker-compose.yml 文件:
version: '2'
services:
wildcat:
build:
context: .
args:
JSPM_GITHUB_AUTH_TOKEN:
image: "nfl/react-wildcat-example:latest"
environment:
NODE_ENV: development
PORT: 3000
STATIC_PORT: 4000
COVERAGE:
LOG_LEVEL:
NODE_TLS_REJECT_UNAUTHORIZED: 0
CHOKIDAR_USEPOLLING: 'true'
volumes:
- ./src:/src/src
- ./api:/src/api
ports:
- "3000:3000"
- "4000:4000"
ulimits:
nproc: 65535
entrypoint: "npm run"
command: "dev"
在这上面花了一两天后我发现了问题,行:
ignored: /\.(git|gz|map)|node_modules|jspm_packages|src/,
导致 chokidar 忽略 /src
这是我将所有源代码复制到 docker 容器中的文件夹。我将 Dockerfile 中的这条路径和 docker-compose.yml 更改为 /code
,一切都按预期工作。
Chokidar 文档 states:
希望对那些以标题来到这里的人有所帮助
It is typically necessary to set this (polling) to true to successfully watch files over a network, and it may be necessary to successfully watch files in other non-standard situations.
在 Docker Desktop for Mac 4.0.0 上,我使用 Firebase Emulators(使用 Chokidar)查看 host-side 文件更改:
environments:
- CHOKIDAR_USEPOLLING=true
我正在使用 docker 用于 mac 版本 1.12.0-rc2 的反应项目。我的工作流程是这样的:
src/
OS X 上的文件夹已安装到容器- 当开发人员修改
src/
中的文件时,它会转换为 ES5 并放置在public/
中(这有效)。 - 当文件在
public/
中更改时,另一个观察者触发热重新加载(在我的本地主机上工作,但在容器中不工作)。
这是第 3 步中我的计步器代码:
// root = "/src"
const watcher = chokidar.watch(root, {
usePolling: true,
awaitWriteFinish: {
pollInterval: 100,
stabilityThreshold: 250
},
ignored: /\.(git|gz|map)|node_modules|jspm_packages|src/,
ignoreInitial: true,
persistent: true
})
.on("change", function fileWatcher(filename) {
const modulePath = filename.replace(`${root}/`, "");
wss.clients.forEach(function sendFileChange(client) {
send("filechange", modulePath, client);
});
if (cache[filename]) {
wss.clients.forEach(function sendCacheFlush(client) {
send("cacheflush", filename, client);
});
delete cache[filename];
}
});
还有我的 docker-compose.yml 文件:
version: '2'
services:
wildcat:
build:
context: .
args:
JSPM_GITHUB_AUTH_TOKEN:
image: "nfl/react-wildcat-example:latest"
environment:
NODE_ENV: development
PORT: 3000
STATIC_PORT: 4000
COVERAGE:
LOG_LEVEL:
NODE_TLS_REJECT_UNAUTHORIZED: 0
CHOKIDAR_USEPOLLING: 'true'
volumes:
- ./src:/src/src
- ./api:/src/api
ports:
- "3000:3000"
- "4000:4000"
ulimits:
nproc: 65535
entrypoint: "npm run"
command: "dev"
在这上面花了一两天后我发现了问题,行:
ignored: /\.(git|gz|map)|node_modules|jspm_packages|src/,
导致 chokidar 忽略 /src
这是我将所有源代码复制到 docker 容器中的文件夹。我将 Dockerfile 中的这条路径和 docker-compose.yml 更改为 /code
,一切都按预期工作。
Chokidar 文档 states:
希望对那些以标题来到这里的人有所帮助It is typically necessary to set this (polling) to true to successfully watch files over a network, and it may be necessary to successfully watch files in other non-standard situations.
在 Docker Desktop for Mac 4.0.0 上,我使用 Firebase Emulators(使用 Chokidar)查看 host-side 文件更改:
environments:
- CHOKIDAR_USEPOLLING=true