create-react-app 打包部署

方法一

function getServedPath(appPackageJson) {
  const publicUrl = getPublicUrl(appPackageJson);
  const servedUrl =
    envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : './');
  return ensureSlash(servedUrl, true);
}
修改config/paths.js中37行,即可
image.png
yarn build

打包后,直接路径nginx挂载路径直接到build下,http://localhost:9001即可成功访问

 server {
        listen       9001;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   D:\workspace\citysimulate\build;
            autoindex on;
      }
}

方法二

访问路径需要带上项目名称,如http://locahost:9001/citySimulate
同样需要修改修改config/paths.js中37行,如上面图中所示
然后:

    
        
            ...
        
    

HashRouter中添加basename属性

你可能感兴趣的:(create-react-app 打包部署)