這是我第一次嘗試vue-cli,爲了避免在全球範圍內安裝npm-packages,我使用了Vagrant。爲什麼LiveReload不適用於vagrant的vue-cli項目?
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.hostname="vagrant"
config.vm.network "forwarded_port", guest: 8080, host: 4545
config.vm.synced_folder ".", "/home/project"
config.vm.provision :shell, path: "provision.sh", privileged: false
end
provision.sh
#!/usr/bin/env bash
# installing packages
sudo apt update
sudo apt install build-essential libssl-dev -y
# installing nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
source ~/.nvm/nvm.sh
# installing node
nvm install node
nvm alias default node
nvm use node
# installing vue-cli
npm install -g vue-cli
初始化項目並安裝:
vue init webpack my-project
npm install
項目結構:
.
├── my-project
│ ├── build
│ ├── config
│ ├── index.html
│ ├── node_modules
│ ├── package.json
│ ├── README.md
│ ├── src
│ ├── static
│ └── test
├── provision.sh
└── Vagrantfile
運行命令NPM運行後開發出現兩個警告:
(node:1787) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Exited with code 3
(node:1787) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
但一切工作
DONE Compiled successfully in 4188ms
> Listening at http://localhost:8080
而且我可以看到我的localhost:4545
運行項目,然後我編輯Hello.vue文件並保存。即使強制重新啓動,瀏覽器也不會更改。
在終端中,它也沒有改變它處於待機模式。
的變化將是可見的只有中斷命令npm run dev
並重新運行。
下面寫了正確的答案,我的CPU使用率與'watchOptions'一起達到了100%,所以我將它備份到poll:1500,忽略:/ node_modules /'。 –