2016-05-09 90 views
-1

我想在require配置中創建一個不存在的模塊,但只有加載依賴關係。例如:Requirejs創建空模塊作爲依賴加載程序

window["requirejs"].config({ 
      paths: { 
       main : "/Scripts/" + "/main", 
       jquery : "/Scripts/" + "/jquery-2.1.3.min", 
       HiChartsWithExtensions : false,//what to put here??? 
       HighCharts : "/Scripts/" + "/HighCharts/highcharts", 
       HighChartsExporting : "/Scripts/" + "/HighCharts/modules/exporting", 
       HighChartsExportingCsv : "/Scripts/" + "/HighCharts/modules/export-csv", 
      } 
      , shim : { 
       main : { 
       deps : ["HiChartsWithExtensions"] 
       }, 
       HiChartsWithExtensions : { 
       deps : ["HighChartsExporting"] 
       }, 
       HighCharts: { 
       deps : ["jquery"], 
       exports: '$' 
       }, 
       "HighChartsExporting" : { 
       deps : ["HighCharts"] 
       }, 
       "HighChartsExportingCsv" : { 
       deps : ["HighChartsExporting"] 
       } 
      } 
}); 
window["require"](['main']); 

如主要取決於HiChartsWithExtensions但requirejs嘗試加載一個js文件它。我希望HiChartsWithExtensions加載依賴關係,而無需實際返回任何內容。

回答

1

現在;以下解決方案有所幫助:

window["requirejs"].config({ 
      paths: { 
       main : "/Scripts/" + "/main", 
       jquery : "/Scripts/" + "/jquery-2.1.3.min", 
       HiChartsWithExtensions : "/Scripts/" + "/HighCharts/modules/export-csv", 
       //deepest dependency here (csv depends on exporting depends on highcharts) 
       HighCharts : "/Scripts/" + "/HighCharts/highcharts", 
       HighChartsExporting : "/Scripts/" + "/HighCharts/modules/exporting", 
       HighChartsData : "/Scripts/" + "/HighCharts/modules/data", 
       HighChartsDrilldown : "/Scripts/" + "/HighCharts/modules/drilldown" 
      } 
      , shim : { 
       main : { 
       deps : ["HiChartsWithExtensions"] 
       }, 
       HiChartsWithExtensions : { 
       deps : ["HighChartsExporting","HighChartsData","HighChartsDrilldown"] 
       }, 
       HighCharts: { 
       deps : ["jquery"], 
       exports: '$' 
       }, 
       "HighChartsExporting" : { 
       deps : ["HighCharts"] 
       }, 
       "HighChartsData" : { 
       deps : ["HighCharts"] 
       }, 
       "HighChartsDrilldown" : { 
       deps : ["HighCharts"] 
       } 
      } 
}); 
window["require"](['main']);