使用AMD生成输出require()构造

时间:2015-05-12 13:57:41

标签: requirejs typescript amd

我目前有一组RequireJs模块定义为:

require(['dep1', 'dep2'], function(dep2, dep2) {
    ...
});

我希望将它们转换为TypeScript模块,但AMD代使用define()构造输出它们:

define(['dep1', 'dep2'], function(dep2, dep2) {
    ...
});

我可以看到它们基本上是等价的。但是我一直在以下基础上工作:

  • 定义:当您希望能够将模块传递到其他模块时。
  • 需要:当需要执行模块时

这些假设是多余的吗?或者有没有办法指示TypeScript输出模块的require()构造?

2 个答案:

答案 0 :(得分:1)

Are these assumptions redundant?

Yes. Sub addLabel() Dim theLabel As Object Dim theRanker As Object Dim labelCounter As Long Dim RowCount As Integer RowCount = Sheets("Overview").Range("A" & Rows.count).End(xlUp).Row For labelCounter = 1 To RowCount Set theRanker = CriteriaPairwiseForm.Controls.Add("Forms.ComboBox.1", "Rating" & labelCounter, True) With theRanker .Left = 20 .Width = 150 .Top = 30 * labelCounter .AddItem "Equal Importance" .AddItem "Moderate Importance" .AddItem "Strong Importance" .AddItem "Very Strong Importance" .AddItem "Extreme Importance" End With Set theLabel = CriteriaPairwiseForm.Controls.Add("Forms.Label.1", "CriteriaRank" & labelCounter, True) With theLabel .caption = Cells(labelCounter, 1).Value .Left = 200 .Width = 150 .Top = 30 * labelCounter End With Next labelCounter End Sub should only be used when you want to lazy load.

is there a way to instruct TypeScript to output the require() construct for a module

Yes. Use the requirejs definition : https://github.com/borisyankov/DefinitelyTyped/blob/master/requirejs/require.d.ts and write code to call the require function manually.

答案 1 :(得分:-1)

您可以使用require()手动编写一个文件来加载其他模块,或者在加载data-main的元素上使用require.js属性。