hmdne / roda-sprockets

MIT License
5 stars 1 forks source link

When set ENV `RACK_ENV=production`, `rake assets:precompile` always raise error if set cache option follow README #8

Closed zw963 closed 3 years ago

zw963 commented 3 years ago

Following is my config:

plugin :sprockets,
    public_path: 'public/assets', # 运行 task生成 assets 的目标文件夹.
    path_prefix: '/assets',  # 生成 link 的时path 的前缀.
    opal: true,
    js_compressor: Terser.new,
    css_compressor: :sassc,
    debug: ENV['RACK_ENV'] != 'production',
    cache: Sprockets::Cache::MemoryStore.new(65536) if ENV['RACK_ENV'] == 'development'

After i set the cache option,when run RACK_ENV=production rake assets:precompile, always raise following error.

      01 NoMethodError: undefined method `sprockets_options' for App:Class
      01 /home/deployer/apps/marketbet_crawler_production/shared/bundle/ruby/3.0.0/bundler/gems/roda-sprockets-2537bc5e79b5/lib/roda/plugins/sprockets_task.rb:22:in `sprockets_options'
      01 /home/deployer/apps/marketbet_crawler_production/shared/bundle/ruby/3.0.0/bundler/gems/roda-sprockets-2537bc5e79b5/lib/roda/plugins/sprockets_task.rb:15:in `update_values'
      01 /home/deployer/apps/marketbet_crawler_production/shared/bundle/ruby/3.0.0/bundler/gems/roda-sprockets-2537bc5e79b5/lib/roda/plugins/sprockets_task.rb:11:in `block in initialize'
      01 /home/deployer/apps/marketbet_crawler_production/shared/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/rake/sprocketstask.rb:107:in `initialize'
      01 /home/deployer/apps/marketbet_crawler_production/shared/bundle/ruby/3.0.0/bundler/gems/roda-sprockets-2537bc5e79b5/lib/roda/plugins/sprockets_task.rb:11:in `initialize'
      01 /home/deployer/apps/marketbet_crawler_production/shared/bundle/ruby/3.0.0/bundler/gems/roda-sprockets-2537bc5e79b5/lib/roda/plugins/sprockets_task.rb:47:in `new'
      01 /home/deployer/apps/marketbet_crawler_production/shared/bundle/ruby/3.0.0/bundler/gems/roda-sprockets-2537bc5e79b5/lib/roda/plugins/sprockets_task.rb:47:in `define!'
      01 /home/deployer/apps/marketbet_crawler_production/releases/20210821100809/lib/tasks/assets.rake:6:in `block (2 levels) in <top (required)>'
      01 /home/deployer/apps/marketbet_crawler_production/shared/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/lib/bundler/cli/exec.rb:63:in `load'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/lib/bundler/cli/exec.rb:63:in `kernel_load'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/lib/bundler/cli/exec.rb:28:in `run'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/lib/bundler/cli.rb:474:in `exec'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/lib/bundler/cli.rb:30:in `dispatch'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/lib/bundler/cli.rb:24:in `start'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/exe/bundle:49:in `block in <top (required)>'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/lib/bundler/friendly_errors.rb:128:in `with_friendly_errors'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/gems/bundler-2.2.22/exe/bundle:37:in `<top (required)>'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/bin/bundle:23:in `load'
      01 /home/deployer/.rvm/gems/ruby-3.0.2/bin/bundle:23:in `<main>'
hmdne commented 3 years ago

I'm quite sure that... looking at your application, you probably don't load the full App before the task happens.

hmdne commented 3 years ago

Oh, now I see. It's operation order. You should do something like:

plugin :sprockets,
    public_path: 'public/assets', # 运行 task生成 assets 的目标文件夹.
    path_prefix: '/assets',  # 生成 link 的时path 的前缀.
    opal: true,
    js_compressor: Terser.new,
    css_compressor: :sassc,
    debug: ENV['RACK_ENV'] != 'production',
    cache: (Sprockets::Cache::MemoryStore.new(65536) if ENV['RACK_ENV'] == 'development')
zw963 commented 3 years ago

Oops, thanks for point out, i meet this type issue again ....