如果您还在后端部分使用 nodemon 并在那里遇到相同的问题,您可以使用 --legacy-watch 标志(短 -L) 也开始轮询.npm exec nodemon -- --legacy-watch --watch src src/main.js 或在 package.json 中:脚本":{服务":nodemon --legacy-watch --watch src src/main.js"}文档:nodemon legacy watchWhen starting a new Vue.js Webpack template project from the terminal with the Vue CLI (I did this inside a docker webpack container that I built with Vue CLI installed) using the documented startup commands (found in the repo here: https://github.com/vuejs-templates/webpack) my webpack-dev-server does not detect changes to my files.$ npm install -g vue-cli$ vue init webpack my-project$ cd my-project$ npm install$ npm run devOnce the webpack-dev-server comes up listening on 0.0.0.0:8080 I can access the the server and I see the proper vue project sample rendered in the browser. HOWEVER when I change one of the files, the webpack server compilation status (container command line / logs) does not update and no changes are visible in the browser.I saw someplace that sometimes webpack will have trouble if a directory it is attempting to monitor has additional characters attached to it but that does not appear to be the case when I do:$ ls 解决方案 It seems that some Docker containers do not support native file watchers which leads to problems detecting file changes. You can solve this by using the active polling mechanism from the webpack dev server. You should only activate this if the devServer is not reacting to changes:vue.config.jsmodule.exports = { devServer: { watchOptions: { poll: true, // or use an integer for a check every x milliseconds, e.g. poll: 1000, ignored: /node_modules/ // otherwise it takes a lot of time to refresh } }};source: documentation webpack watchOptionsIf you are also using nodemon in the back-end part and having the same issue there, you can solve it by using the --legacy-watch flag (short -L) which starts polling too.npm exec nodemon -- --legacy-watch --watch src src/main.jsor in package.json:"scripts": { "serve": "nodemon --legacy-watch --watch src src/main.js"}documentation: nodemon legacy watch 这篇关于为什么在与新的 Vue.js CLI Webpack 模板项目一起使用时,Webpack-Dev-Server(在 docker 容器内)不检测文件更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 01:28