要求创建空模块作为依赖项加载程序

Requirejs create empty module to serve as a dependency loader

本文关键字:依赖 加载 程序 创建 模块      更新时间:2023-09-26

我想在require-config中创建一个不存在但仅用于加载依赖项的模块。例如:

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']);

Where main依赖于HiChartsWithExtensions,但requirejs试图为其加载一个js文件。我希望HiChartsWithExtensions加载依赖项,而该模块实际上不返回任何内容。

目前;以下解决方案有所帮助:

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']);