尝试在Laravel Homestead(VirtualBox + Vagrant)中运行npm run serve(vue-cli应用程序)

时间:2019-05-05 09:51:45

标签: npm homestead vue-cli-3

我有一个vue-cli应用,试图在Laravel Homestead中运行它。

我有什么

我在主机上的hosts

127.0.0.1   localhost
127.0.1.1   PC
192.168.2.10 myvueapp.local

hosts在VM内:

127.0.0.1       localhost
127.0.0.1       myvueapp.local
127.0.1.1       homestead       homestead

流浪者版本:2.2.4,宅基地:v8.3.2,vue --version:3.7.0

npm run serve在VM内执行没有问题,但是我得到了

  

很抱歉,没有JavaScript,myvueapp无法正常工作   已启用。请启用它以继续。

作为请求的响应正文:

//response headers
Request URL: https://myvueapp.local/
Request Method: GET
Status Code: 200 
Remote Address: 192.168.2.10:443
Referrer Policy: no-referrer-when-downgrade

浏览器页面为空白。

还有一个favicon请求:

Request URL: https://myvueapp.local/%3C%=%20BASE_URL%20%%3Efavicon.ico
Request Method: GET
Status Code: 400 Bad Request
Remote Address: 192.168.2.10:443

以某种方式BASE_URL不能在index.html中进行编译:

<link rel="icon" href="<%= BASE_URL %>favicon.ico">

我的vue.config.js

module.exports = {
  devServer: {
    host: 'myvueapp.local',
    https: true
  }
}

Homestead.yaml

ip: "192.168.2.10"
#...
sites:
    - map: myvueapp.local
      to: /home/vagrant/path/to/myvueapp.local/public
#...
ports:
    - send: 8080
      to: 80

服务Vue的端口(在VM中,8080)正在侦听。

lsof -i :8080
COMMAND  PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node    3022 vagrant   22u  IPv4  31440      0t0  TCP localhost:http-alt (LISTEN)

Nginx配置:

server {
    listen 80;
    listen 443 ssl http2;
    server_name .myvueapp.local;
    root "/path/to/myvueapp.local/public";

    index index.html index.htm index.php;

    charset utf-8;



    location / {
        try_files $uri $uri/ /index.php?$query_string;

    }

P。 S.当我从主机上提供服务时,它运行正常。

我尝试过的事情

change host

module.exports = {
  devServer: {
    host: '0.0.0.0', //<-- here
    https: true
  }
}

,没有帮助。


编辑#1

我又走了一步,这个Nginx配置现在允许我使用主机访问VM内提供的Vue应用程序:

   location / {
        try_files $uri $uri/ /index.html =404;
        proxy_pass http://localhost:8080; #<-- this might be the output from npm run serve, without last slash
        #  App running at:
        #  - Local:   http://localhost:8080/
        #             ^^^^^^^^^^^^^^^^^^^^^
   }

但是仍然存在一个问题:热重装不起作用。

0 个答案:

没有答案