程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在Google App Engine上部署create-react-app大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决在Google App ENGIne上部署create-react-app?

开发过程中遇到在Google App ENGIne上部署create-react-app的问题如何解决?下面主要结合日常开发的经验,给出你关于在Google App ENGIne上部署create-react-app的解决方法建议,希望对你解决在Google App ENGIne上部署create-react-app有所启发或帮助;

经过多次搜索,我发现我的应用程序的路由系统是原因。

如本文所述,我们在编写app.yaml时需要格外小心。如果我们首先编写以下项目,则GAE将返回build/index.HTML所有查询,包括对/static/Js和的访问/static/CSS

- url: /
  static_files: build/index.HTML
  upload: build/index.HTML

create-react-app为创建一个构建文件夹和静态子文件夹npm run build。因此,我必须像这样更具体地编写我的app.yaml:

handlers:
  - url: /static/Js/(.*)
    static_files: build/static/Js/\1
    upload: build/static/Js/(.*)
  - url: /static/CSS/(.*)
    static_files: build/static/CSS/\1
    upload: build/static/CSS/(.*)
  - url: /static/media/(.*)
    static_files: build/static/media/\1
    upload: build/static/media/(.*)
  - url: /(.*\.(Json|ico))$
    static_files: build/\1
    upload: build/.*\.(Json|ico)$
  - url: /
    static_files: build/index.HTML
    upload: build/index.HTML
  - url: /.*
    static_files: build/index.HTML
    upload: build/index.HTML

解决方法

我正在尝试在Google App ENGIne上部署使用create-react-app创建的应用程序。

我的应用程序在本地(npm startnpm run build &serve-sbuild)都可以正常运行。但是,在Google App
ENGIne上部署的应用程序仅显示index.html,并且不会调用我的react代码。

Chrome开发者控制台显示Uncaught SyntaxError: Unexpected token <

另外,我在console.cloud.google.com上发现,已部署的应用程序不包含构建文件夹。这样对吗?

任何人都可以解决这个问题?

这是我的package.json:

{
  "name": "XXXXX","version": "0.1.0","private": true,"dependencies": {
    "react": "^16.8.2","react-dom": "^16.8.2","react-ga": "^2.5.7","react-router-dom": "^4.3.1","react-scripts": "2.1.5"
  },"scripts": {
    "start": "react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject"
 },"eslintConfig": {
    "extends": "react-app"
  },"browserslist": [
    ">0.2%","not dead","not ie <= 11","not op_mini all"
  ]
}

另外,这是我的app.yaml。

runtime: nodejs10

handlers:
- url: /.*
  static_files: build/index.html
  upload: build/index.html
- url: /
  static_dir: build

大佬总结

以上是大佬教程为你收集整理的在Google App Engine上部署create-react-app全部内容,希望文章能够帮你解决在Google App Engine上部署create-react-app所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:在Google