本文介绍了使用RequireJS加载页面时,FineUploader出现MegaPixImage错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重构我的应用程序以使用RequireJS(在Play Framework中使用sbt-web抽象,但这并不紧密).

I am refactoring my application to use RequireJS (using the sbt-web abstraction in Play Framework, but that isn't germane).

首先,我简单地尝试使用填充程序加载FineUploader,因为它与AMD不兼容,但是我遇到了"未定义MegaPixImage "错误.这对我来说很奇怪,因为FineUploader没有依赖项(因为内置了第三方的东西).

First, I simply sought to use a shim to load FineUploader since it isn't AMD-compatible, but I encountered a "MegaPixImage is not defined" error. That seemed weird to me since FineUploader has no dependencies (as third-party stuff is built-in).

但是在看到此Stack Overflow帖子后,我下载了并以这种方式(在CoffeeScript中)设置我的RequireJS配置:

But after seeing this Stack Overflow post, I downloaded the library separately and set up my RequireJS configuration this way (in CoffeeScript):

requirejs.config(
  paths:
    megapiximage: './megapiximage'
    fineUploader: './custom.fineuploader'
  shim:
    fineUploader:
      exports: 'fineUploader'
      deps: ['jquery', 'megapiximage' ]
)

require(['./main'], (main) ->
  require(['fineUploader', './myfile'])

  return
)

但是,即使该库与AMD兼容,我仍然会遇到相同的错误.

However, I still get the same error even though the library is AMD-compatible.

对我应该如何设置RequireJS配置的任何见解都将受到赞赏.

Any insight into how I should set up my RequireJS configuration is appreciated.

推荐答案

FineUploader包引用了"MegaPixImage"变量,因此您需要使其可用.我认为以下方法应该有效:

The FineUploader package references the 'MegaPixImage' variable, so you need to make that available. I think the following should work:

require(['fineUploader', 'megapiximage'], function(fineUploader, MegaPixImage) {
    // initialize your fineuploader here
})

请注意,您实际上已经两次包含了MegaPixImage库.因此,我决定将FineUploader排除在我的RequireJS设置之外,并将其作为单独的javascript文件添加到HTML中.

Note that you have actually included the MegaPixImage library twice now. I therefore decided to keep FineUploader out of my RequireJS setup and add it as a seperate javascript file in the HTML.

这篇关于使用RequireJS加载页面时,FineUploader出现MegaPixImage错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 22:11