我已经在importmap-rails gem的Github仓库这里开了一个问题,但我想在这里提出问题,以防有人能提供解决方案。
到目前为止,我发现以下情况:
使用
调用
到目前为止,我发现以下情况:
使用
rails plugin new custom_page --mountable --full
在Rails 7 alpha2或Rails 7.0中生成的新引擎将importmap-rails gem包含在捆绑的gems中,但无法使用。在enginename.gemspec中添加spec.add_dependency 'importmap-rails'
没有任何效果,也不会在engine.rb中添加require importmap-rails
。bin目录中没有importmap可执行文件。调用
bundle info importmap-rails
会产生一个有希望的结果,显示默认安装了该gem。* importmap-rails (0.8.1)
Summary: Use ESM with importmap to manage modern JavaScript in Rails without transpiling or bundling.
Homepage: https://github.com/rails/importmap-rails
Source Code: https://github.com/rails/importmap-rails
Path: /home/jamie/.rvm/gems/ruby-3.0.0@custom_page/gems/importmap-rails-0.8.1
运行rails --tasks
命令会显示:
rails app:importmap:install # Setup Importmap for the app
我认为这是由--full选项生成的测试应用程序引起的,而不是作为引擎的rails命令可用。 我期望看到相同的内容,而没有app:前缀。 对该任务的调用会导致模板错误,如下所示。
rails app:importmap:install
不知道如何构建任务'app:template'(查看可用任务列表:
rails --tasks
)。您是不是想说'app:tmp:create'
如果有解决此问题的变通方法,我会非常感激听到它,我相信其他人也是如此。我之所以想要解决这个问题,是因为我在Rails 6.1.4引擎中完全无法介绍Webpacker,而我希望这将成为我的改进解决方案。
app:template
,但应该有app:app:template
。我的解决方法是创建一个别名 rake 任务来绕过此错误。在您的 rake 文件中:desc 'Alias to app:app:template' task template: :environment do Rake::Task['app:app:template'].invoke end
- gillien