1. 程式人生 > >npm run build生產環境打包部署

npm run build生產環境打包部署

1、npm run build打包成功後,會在dist目錄下生成index.html和static資料夾,將dist下所有檔案複製到你需要的目錄下。

2、配置nginx,以下為簡單配置:

server {

        listen 8011  default;

        server_name  localhost;

        location / {

#配置網站根目錄,即index.html和static所在的路徑

                root   /Users/wqz/git/outdoor-ui/dist;

                try_files $uri $uri/ /index.html last;

                index  index.html;

                add_header Access-Control-Allow-Origin *;

        }

#配置跨域轉發,如果你的專案有需要請求其他伺服器資料的需要配置,否則可以不用

        location /auth/ {

               proxy_pass http://127.0.0.1:9002;

        }

        location /admin/ {

                proxy_pass http://127.0.0.1:9002;

        }

        access_log  logs/outdoor-ui.access.log;

}

配置完後,重新載入nginx配置,使用命令sudo nginx -s reload , 如果未啟動,直接啟動就可以了。

3、訪問localhost:8011即可。