requirejs没有正确加载对象

时间:2018-03-11 19:44:28

标签: javascript angularjs requirejs grunt-contrib-requirejs cornerstone

我正在使用requirejs

配置angularjs项目依赖项

以下是配置

"cornerstone-core":"emp/cornerstone.min",
"cornerstone-math":"emp/cornerstoneMath.min",
"hammer":"emp/hammer.min",
"properties":"emp/properties"
"clientParameters":"emp/clientParameters"
"cornerstone":"emp/cornerstone"
"cornerstoneMath":"emp/cornerstoneMath"
"cornerstoneTools":"emp/cornerstoneTools"
"cornerstoneWADOImageLoaderCodecs":"emp/cornerstoneWADOImageLoaderCodecs"
"cornerstoneWADOImageWebWorker":"emp/cornerstoneWADOImageWebWorker"
"myApp":"emp/myApp"

运行时依赖项是,

clientParameters : [ "properties" ],
cornerstoneMath : [ "properties", "clientParameters", "cornerstone-core", "cornerstone-math", "hammerjs" ]
cornerstone : [ "properties", "clientParameters", "cornerstone-core", "cornerstone-math", "hammerjs" ],
cornerstoneTools : [ "properties", "clientParameters", "cornerstone-core", "cornerstone-math", "hammerjs" ],
myApp : [ "properties", "clientParameters", "cornerstone", "cornerstoneMath", "cornerstone-core", "cornerstone-math", "hammerjs" ]

在cornerstone.js中,我按以下方式加载模块,

(function webpackUniversalModuleDefinition(root, factory) {
  if(typeof exports === 'object' && typeof module === 'object')
    module.exports = factory();
  else if(typeof define === 'function' && define.amd)
    define("cornerstone", [], factory); // error line
  else if(typeof exports === 'object')
    exports["cornerstone"] = factory(); 
  else
    root["cornerstone"] = factory();
})(this, function() {
return (function(modules) {

我收到以下错误,

     myApp.js:2312 Uncaught(in promise) ReferenceError: cornerstone is not defined

在第define("cornerstone", [], factory);行时当我用root["cornerstone"] = factory();替换错误行时,一切正常。

[编辑]
factory方法是在这个问题中使用的bootstrapper:Trying to understand Webpack

1 个答案:

答案 0 :(得分:1)

因为您使用的是模块,所以首先必须导入corerstone。使用AMD模块,它看起来像:

define(["angular", "cornerstone"], function (angular, cornerstone) {
    ....
});