简体   繁体   English

如何使用 Rails 6 在 Heroku 上安装 Webpacker

[英]How do I install Webpacker on Heroku with Rails 6

I am trying to install a Rails 6 app to Heroku with Webpacker我正在尝试使用 Webpacker 将 Rails 6 应用程序安装到 Heroku

The git push heroku command seems to trigger the whole build proces git push heroku 命令似乎触发了整个构建过程

The node.js is invoked successfully and completes. node.js 被成功调用并完成。

devDependencies then get pruned apparently. devDependencies 然后显然会被修剪。

Then the ruby buildpack kicks in which installs all of the ruby gems and "detects rake tasks" during which it runs rake assets:precompile然后 ruby buildpack 开始安装所有 ruby gems 并“检测 rake 任务”,在此期间它运行 rake assets:precompile

Then I get:然后我得到:

Compilation failed:
CLI for webpack must be installed.
webpack-cli (https://github.com/webpack/webpack-cli)

I am pretty sure I need to run我很确定我需要跑步

bin/rails webpacker:install

somewhere before asset compilation starts, but there is no chance to customise the build script as there is with node.js package.json script hooks for prebuild and postbuild from what I can see and I just end up with:在资产编译开始之前的某个地方,但是没有机会像 node.js package.json 脚本钩子一样自定义构建脚本

Precompiling assets failed.
Push rejected, failed to compile Ruby app.

So how am I supposed to get around this and get webpacker installed properly before heroku tries to compile the assets?那么在 heroku 尝试编译资产之前,我应该如何解决这个问题并正确安装 webpacker?

I think the solution is that because I am running 2 buildpacks in sequence, node.js followed by ruby, I need to prevent the node.js buildpack from pruning the devdependencies (ie webpack) defined in package.json as: I think the solution is that because I am running 2 buildpacks in sequence, node.js followed by ruby, I need to prevent the node.js buildpack from pruning the devdependencies (ie webpack) defined in package.json as:

  "devDependencies": {
    "webpack-cli": "^4.3.1",
    "webpack-dev-server": "^3.11.1"
  },

by:经过:

echo Setting Heroku to not prune dev dependencies
heroku config:set NPM_CONFIG_PRODUCTION=false YARN_PRODUCTION=false

The net result is I think that when the ruby buildpack comes to call the assets:precompile rake task that the webpacker CLI is still installed whereas previously it was not.最终结果是,我认为当 ruby buildpack 调用 assets:precompile rake 任务时,仍然安装了 webpacker CLI,而之前没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM