【问题标题】:Using Meteor with Requirejs在 Requirejs 中使用 Meteor
【发布时间】:2014-10-11 22:02:35
【问题描述】:

如何将 requirejs 集成到流星应用程序中并使用 AMD 模块,例如用于我的 Backbone 模块? 有没有人这样做并且可以告诉我需要哪些步骤才能使其正常工作?

【问题讨论】:

    标签: javascript requirejs meteor amd


    【解决方案1】:

    一个简单的答案(尽管可能不是您要寻找的答案)是您可以简单地独立使用这两者。换句话说,加载所有流星脚本,然后开始加载所需的脚本。您的 require-ified 脚本将能够很好地使用 Meteor 的东西,而不必通过 Require 的加载器“导入”任何它。

    如果你想要必须导入它,你应该为它创建一个 Require "shim"。

    【讨论】:

    • 上次我玩流星 (v0.4) 时它没有 require/commonjs 支持。我认为唯一真正的选择是/是为流星编写自己的包装插件,或者手动将所需的文件复制到流星文件系统中。
    • @machineghost:谢谢,这听起来很合理
    • @crapthings:我认为这是 node 中的 commonjs 导入
    【解决方案2】:

    这是我在 Meteor 和 IronRouter 中加载 Aloha Editor 的方式。 Aloha 使用 requirejs 加载其所有依赖项。

    1. public/alohaeditor 中解压缩 Aloha 发行版。
    2. 将所有 Aloha css 文件(aloha-common-extra.css 除外)移至 client/lib/alohaeditor(不要忘记插件文件夹中的文件)。
    3. 在所有 Aloha css 文件中,将相对路径转换为绝对路径(将所有 '../' 替换为 '/alohaeditor/')。
    4. 安装wait-on-lib Meteor 包。
    5. 将以下钩子添加到您的路线:

      onBeforeAction: function(pause)
          {           
          // Dynamically load require.js
          var one = IRLibLoader.load('/alohaeditor/lib/require.js', 
              {
              success: function(){ console.log('Successfully loaded require.js'); },
              error: function(){ console.log('Error loading require.js'); }
              });
          if(!one.ready())
              return pause();
      
          // Aloha settings
          Aloha = window.Aloha || {};
          Aloha.settings = Aloha.settings || {};
          Aloha.settings.baseUrl = '/alohaeditor/lib/';
          Aloha.settings.plugins = Aloha.settings.plugins || {};
          Aloha.settings.plugins.load = 'common/ui, common/format, common/link, common/table, common/list, common/block, common/undo, common/contenthandler, common/paste, common/commands, common/abbr';
      
          // Dynamically load aloha.js
          var two = IRLibLoader.load('/alohaeditor/lib/aloha.js',
              {
              success: function(){ console.log('Successfully loaded aloha.js'); },
              error: function(){ console.log('Error loading aloha.js'); }
              });
          if(!two.ready())
              return pause();
          },
      

    【讨论】:

      猜你喜欢
      • 2016-07-16
      • 2013-10-10
      • 2013-02-19
      • 2013-07-02
      • 2012-11-05
      • 2012-06-27
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多