Javascript 使用Rails 5导入网页包

Javascript 使用Rails 5导入网页包,javascript,webpack,ruby-on-rails-5,Javascript,Webpack,Ruby On Rails 5,我有一个相当大的代码库,我正试图从Rails 4迁移到Rails 5,其中一个主要部分是从资产管道过渡到webpack,以管理需求和包 <!DOCTYPE html> <html> <% content_for :extra_head_scripts do %> <% end %> <head> <title>Cloverhound</title> <meta name="vie

我有一个相当大的代码库,我正试图从Rails 4迁移到Rails 5,其中一个主要部分是从资产管道过渡到webpack,以管理需求和包

<!DOCTYPE html>
<html>
  <% content_for :extra_head_scripts do %>
  <% end %>
  <head>
    <title>Cloverhound</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <%= javascript_pack_tag "application-editor", 'data-turbolinks-track': 'reload' %>
    <%= stylesheet_link_tag "application-editor", :media => "all" %>
    <%= csrf_meta_tags %>
    <%= favicon_link_tag 'favicon.ico' %>
    <%= render partial: "layouts/shared/head_scripts" %>


    <!-- this javascript_tag passes the user's locale to the editor to enable translations -->
    <%= javascript_tag do %>
      I18n.defaultLocale = "<%= I18n.default_locale %>";
      I18n.locale = "<%= current_user.locale.shortcode.to_s %>";
    <% end %>
  </head>
  <body>
    <%= render partial: "shared/svg_sprite" %>
    <%= yield %>
  </body>
</html>

上面是我的简单网页文件,可以正确登录到chrome控制台,但是I18n仍然没有定义。如果我尝试在application-editor.js中调用I18n,它也将返回undefined。但是,如果我将i18n更改为i18n bad或类似的内容,我将得到一个错误,说明找不到模块。这让我相信我的模块正在被发现,但在导入过程中出现了一些问题。我对webpacker很陌生,所以任何想法都会很有帮助

你能用真实的代码替换这些图像吗?这将是更可读的所有社区。完成!对不起,第一个stackoverflow帖子,不太清楚一切是如何运作的yetNo problem man!试着遵循这个指南:另外,我还没有看到你的变化。你已经编辑了你的文章并将图片替换为代码了吗?编辑完成了!实际上,在第二个文件中导入后,我能够调用console.log(I18n.t('hello')),从而取得了一些进展,但第一个文件中的引用仍然返回未定义。我遵循这个指南:你能用真实的代码替换图片吗?这将是更可读的所有社区。完成!对不起,第一个stackoverflow帖子,不太清楚一切是如何运作的yetNo problem man!试着遵循这个指南:另外,我还没有看到你的变化。你已经编辑了你的文章并将图片替换为代码了吗?编辑完成了!实际上,在第二个文件中导入后,我能够调用console.log(I18n.t('hello')),从而取得了一些进展,但第一个文件中的引用仍然返回未定义。我遵循了这个指南:
console.log('Hello World from Webpacker');
console.log("Application-Editor");

import Sortable from 'sortablejs';
//var I18n = require('i18n-js');
import I18n from 'i18n';