最新版本的Rails 6.0.2附带了一个package.json,它使用需要节点8的rails / webpack版本4.2.2。
流行的互联网智慧似乎是使用RAILS_SKIP_ASSET_COMPILATION = true,而是使用包含.ebextension/fix_rails_6.config
的文件
commands:
02_download_nodejs:
command: "curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -"
03_install_nodejs:
command: "yum -y install nodejs"
container_commands:
19_precompile:
command: "bundle exec rake assets:precompile"
(完整文件https://gist.github.com/lettergram/7384acdc3a157579a1692cc0af09d33a)
但是,这会导致错误Webpacker requires Node.js >= 8.16.0 and you are using 6.17.1
...
如何获得预编译以使用已经安装的Node 8?
我现在使用以下命令(找到here)开始工作:
# .ebextension/fix_rails_6.config
commands:
00_remove_node_6_if_present:
command: "/bin/rm -rf /var/cache/yum && /usr/bin/yum remove -y nodejs && /bin/rm /etc/yum.repos.d/nodesource* && /usr/bin/yum clean all && rm -rf /var/cache/yum"
ignoreErrors: true
01_download_nodejs:
command: "curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -"
02_install_nodejs:
command: "yum -y install nodejs"
03_install_yarn:
command: "sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo && sudo yum install yarn -y"
04_mkdir_webapp_dir:
command: "mkdir /home/webapp"
ignoreErrors: true
05_chown_webapp_dir:
command: "chown webapp:webapp /home/webapp"
ignoreErrors: true
06_chmod_webapp_dir:
command: "chmod 0744 /home/webapp"
ignoreErrors: true
07_chmod_logs:
command: "chown webapp:webapp -R /var/app/current/log/"
ignoreErrors: true
08_create_log_file:
command: "touch /var/app/current/log/production.log"
ignoreErrors: true
09_chown_log_production:
command: "chown webapp:webapp /var/app/current/log/production.log"
ignoreErrors: true
10_chmod_log_dir:
command: "chmod 0664 -R /var/app/current/log/"
ignoreErrors: true
11_update_bundler:
command: "gem update bundler"
ignoreErrors: true
12_chown_current:
command: "chown webapp:webapp -R /var/app/current/"
ignoreErrors: true
13_chmod_current:
command: "chmod 0755 -R /var/app/current/"
ignoreErrors: true
14_chown_current:
command: "chown webapp:webapp -R /var/app/ondeck/"
ignoreErrors: true
15_chown_current:
command: "chmod 0644 -R /var/app/ondeck/"
ignoreErrors: true
container_commands:
16_install_webpack:
command: "npm install --save-dev webpack"
17_precompile:
command: "bundle exec rake assets:precompile"
我必须进行更改以确保删除了node 6
并安装了node 12
,而不是在&& rm -rf /var/cache/yum
命令的末尾添加00_remove_node_6_if_present
,因为它仍与原始文件一起安装node 6
。
但是在此之后,我对NGINX代理遇到了更多的痛苦,我决定将webpacker public_output_path
更改为assets
,从而解决了这一问题,因为我决定对所有内容而不是链轮使用webpacker。