Ruby on rails 在使用webpacker部署到heroku后,资产管道中不存在资产
我使用的是rails 5.2.3 我可以在本地下载pdf,但在Heroku上出现错误500 错误为:ActionView::Template::Error(资产管道中不存在资产“pdf.css”): 这是我的heroku日志Ruby on rails 在使用webpacker部署到heroku后,资产管道中不存在资产,ruby-on-rails,heroku,webpack,Ruby On Rails,Heroku,Webpack,我使用的是rails 5.2.3 我可以在本地下载pdf,但在Heroku上出现错误500 错误为:ActionView::Template::Error(资产管道中不存在资产“pdf.css”): 这是我的heroku日志 2019-06-12T20:26:05.707039+00:00 app[web.1]: I, [2019-06-12T20:26:05.706962 #4] INFO -- : [b789ac1d-fe64-434c-b259-a2f3949a7bd0] Rende
2019-06-12T20:26:05.707039+00:00 app[web.1]: I, [2019-06-12T20:26:05.706962 #4] INFO -- : [b789ac1d-fe64-434c-b259-a2f3949a7bd0] Rendered clients/orders/show.pdf.erb within layouts/clients/application.pdf.erb (38.4ms)
2019-06-12T20:26:05.709399+00:00 app[web.1]: I, [2019-06-12T20:26:05.709314 #4] INFO -- : [b789ac1d-fe64-434c-b259-a2f3949a7bd0] Completed 500 Internal Server Error in 55ms (ActiveRecord: 16.2ms)
2019-06-12T20:26:05.710722+00:00 app[web.1]: F, [2019-06-12T20:26:05.710296 #4] FATAL -- : [b789ac1d-fe64-434c-b259-a2f3949a7bd0]
2019-06-12T20:26:05.710724+00:00 app[web.1]: F, [2019-06-12T20:26:05.710384 #4] FATAL -- : [b789ac1d-fe64-434c-b259-a2f3949a7bd0] ActionView::Template::Error (The asset "pdf.css" is not present in the asset pipeline.):
2019-06-12T20:26:05.710726+00:00 app[web.1]: F, [2019-06-12T20:26:05.710579 #4] FATAL -- : [b789ac1d-fe64-434c-b259-a2f3949a7bd0] 1: <html lang="fr">
2019-06-12T20:26:05.710728+00:00 app[web.1]: [b789ac1d-fe64-434c-b259-a2f3949a7bd0] 2: <head>
2019-06-12T20:26:05.710732+00:00 app[web.1]: [b789ac1d-fe64-434c-b259-a2f3949a7bd0] 3: <meta charset="utf-8" />
2019-06-12T20:26:05.710733+00:00 app[web.1]: [b789ac1d-fe64-434c-b259-a2f3949a7bd0] 4: <%= wicked_pdf_stylesheet_link_tag 'pdf' %>
2019-06-12T20:26:05.710734+00:00 app[web.1]: [b789ac1d-fe64-434c-b259-a2f3949a7bd0] 5: </head>
2019-06-12T20:26:05.710736+00:00 app[web.1]: [b789ac1d-fe64-434c-b259-a2f3949a7bd0] 6: <body>
2019-06-12T20:26:05.710737+00:00 app[web.1]: [b789ac1d-fe64-434c-b259-a2f3949a7bd0] 7: <div>
2019-06-12T20:26:05.710739+00:00 app[web.1]: F, [2019-06-12T20:26:05.710659 #4] FATAL -- : [b789ac1d-fe64-434c-b259-a2f3949a7bd0]
2019-06-12T20:26:05.710815+00:00 app[web.1]: F, [2019-06-12T20:26:05.710734 #4] FATAL -- : [b789ac1d-fe64-434c-b259-a2f3949a7bd0] app/views/layouts/clients/application.pdf.erb:4:in `_app_views_layouts_clients_application_pdf_erb___1711932080367152756_47199839415040'
2019-06-12T20:26:05.710823+00:00 app[web.1]: [b789ac1d-fe64-434c-b259-a2f3949a7bd0] app/controllers/clients/orders_controller.rb:19:in `block (2 levels) in show'
2019-06-12T20:26:05.710825+00:00 app[web.1]: [b789ac1d-fe64-434c-b259-a2f3949a7bd0] app/controllers/clients/orders_controller.rb:16:in `show'
pdf文件的存储方式如下vendor/assets/stylesheets/pdf.scss
,在供应商中,我还有一个自定义的引导文件bootstrap.min.css
pdf.scss
@import“bootstrap.min”;
.someclass{}
在config/initializers/assets.rb中,我有一行:
Rails.application.config.assets.precompile += %w( pdf.scss, chartkick.js)
我也在使用webpacker,这可能是问题所在
这是我的webpacker.yml
# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
extensions:
- .jsx
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true
这是一个很长的过程,但是有一个with webpack v4,其中webpack cli
在package.json
配置文件中标记为devDependency
当部署任务运行webpack:compile
且没有webpack cli
时,不会引发错误,因此部署完成但不会在public/packs
文件夹中编译任何文件
要解决此问题,只需将webpack cli
依赖项从devDependencies
移动到dependencies
更新
如果使用capistrano
部署项目,则应将public/packs
和node\u模块
(最后一个是可选的)添加到deploy.rb中的链接目录
:
另外,如果使用节点模块,则必须在预编译资产之前运行yarm:install
。为此,只需将此任务添加到deploy.rb
文件中:
before "deploy:assets:precompile", "deploy:yarn_install"
namespace :deploy do
desc "Run rake yarn install"
task :yarn_install do
on roles(:web) do
within release_path do
execute("cd #{release_path} && yarn install --silent --no-progress --no-audit --no-optional")
end
end
end
end
有关这方面的更多详细信息,请检查capistrano部署
更新2
这是另一个远大的可能性,但有一种可能性,即heroku
buildpacks的顺序可能会影响资产编译过程<代码>节点
buildpack必须先出现,然后是ruby
buildpack。以下内容可以解决此问题:
heroku buildpacks:clear
heroku buildpacks:set heroku/nodejs
heroku buildpacks:add heroku/ruby
同一问题中建议的另一个快速修复方法是在heroku
控制台内运行rake webpacker:compile
,但这并不能解决部署资产编译问题。我添加了my package.json并移动了webpack cli,没有任何更改:(可能是因为您的capistrano
配置。我更新了我的答案,以便您可以查看。我不使用capistrano…当我部署时,我使用git push heroku master…我应该怎么做?@johan我对我的答案进行了另一次更新。希望这一次对您有所帮助。我按照您的建议做了,但没有成功:(供应商
文件夹根本没有编译,也没有本地编译,也没有在heroku上编译。)
heroku buildpacks:clear
heroku buildpacks:set heroku/nodejs
heroku buildpacks:add heroku/ruby