npm run build生产环境打包部署

一、npm run build打包成功后,会在dist目录下生成index.html和static文件夹,将dist下全部文件复制到你须要的目录下。html

二、配置nginx,如下为简单配置:nginx

server {git

        listen 8011  default;npm

        server_name  localhost;跨域

        location / {服务器

#配置网站根目录,即index.html和static所在的路径网站

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

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

                index  index.html;server

                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 , 若是未启动,直接启动就能够了。


三、访问localhost:8011便可。