其他分享
首页 > 其他分享> > create-react-app 打包部署

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行,即可
 

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行,如上面图中所示
然后:

    <Provider store={store}>
        <HashRouter basename="citySimulate">
            ...
        </HashRouter>
    </Provider>

HashRouter中添加basename属性

 

标签:paths,http,create,react,build,9001,const,app,publicUrl
来源: https://www.cnblogs.com/snowhite/p/15458932.html