所以我想出了一个对我有用的解决方案。
因为我想像 Heroku 使用 NodeJS buildpack 那样在服务器上创建我的应用程序的构建版本,所以我必须创建一个命令来安装节点,如下所示:
container_commands:
01_install_node:
command: "curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash - && sudo yum install nodejs"
ignoreErrors: false
然后为了在 Python 环境 EB 上创建 react 应用程序的构建版本,我添加了以下命令:
container_commands:
02_react:
command: "npm install && npm run build"
ignoreErrors: false
所以当然,在构建版本创建后,你应该收集静态文件,所以这是我的工作配置文件最后的样子:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: <project_name>/wsgi.py
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: <project_name>.settings
aws:elasticbeanstalk:container:python:staticfiles:
/static/: staticfiles/
container_commands:
01_install_node:
command: "curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash - && sudo yum install nodejs"
ignoreErrors: false
02_react:
command: "npm install && npm run build"
ignoreErrors: false
03_collectstatic:
command: "django-admin.py collectstatic --noinput"
希望这可以帮助任何遇到相同情况的人🙂