问题
I am refactoring my application to use RequireJS (using the sbt-web abstraction in Play Framework, but that isn't germane).
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).
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
)
However, I still get the same error even though the library is AMD-compatible.
Any insight into how I should set up my RequireJS configuration is appreciated.
回答1:
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
})
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.
来源:https://stackoverflow.com/questions/24983663/megapiximage-error-from-fineuploader-when-loading-page-with-requirejs