簡體   English   中英

使用帶有Requirejs的Meteor

[英]Using Meteor with Requirejs

如何在流星應用程序中集成requirejs並使用AMD模塊,例如我的Backbone模塊? 有沒有人這樣做,可以告訴我需要哪些步驟來實現這個目標?

一個簡單的答案(雖然可能不是您正在尋找的那個)是您可以單獨使用這兩個答案。 換句話說,加載所有的meteor腳本,然后開始加載require-ified腳本。 你需要的腳本可以很好地使用Meteor的東西,而不必通過Require的加載器“導入”任何一個。

如果你想要導入它,你應該為它創建一個Require“shim”。

以下是我在Meteor和IronRouter中加載Aloha Editor的方法。 Aloha使用requirejs加載其所有依賴項。

  1. 公共/ 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(); }, 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM