dudewad
dudewad

Reputation: 13933

RequireJS not loading createjs

I'm following both the requirejs and preloadjs docs to the letter but can't get requirejs to obtain a reference to createjs. Here's my config:

requirejs.config({
    baseUrl: "script/module",
    paths: {
        createjs: "/bower_components/PreloadJS/lib/preloadjs-0.6.1.min"
    },
    shim:{
        "createjs": {
            exports: "createjs"
        }
    }
});

And then in my mainjs:

define(
    ["createjs"],
    function (createjs) {
        //At this point all controllers are loaded and ready to go
        console.log(createjs);
        return {};
    }
);

...but creatjs when logged outputs this obect:

{
    noConflict: ()
    parse: parse()
    runInContext: a(b,d)
    stringify: stringify()
    __proto__: Object
}

What am I missing? Or is this a bug? I'm on require 2.1.2 and preloadjs 0.6.1. This is extremely frustrating because I've used all forms of shims, renaming, and even removed the baseUrl. I've started from scratch multiple times.

Also, I've tried replacing all references to "createjs" with "preloadjs". Problem is that the global object "createjs" is what's available in the global namespace (and as you'd expect I can access it from within requirejs).

I've opened this as a preloadjs issue on github here, but received no response as of yet. https://github.com/CreateJS/PreloadJS/issues/171

Thanks for any help!

Upvotes: 0

Views: 456

Answers (1)

user24950814234
user24950814234

Reputation: 2037

You can take the compiled (minified) createjs code and add the following at the very end to make the entire library a single AMD module.

if (typeof define === "function" && define.amd) {
    define(function() {
        return window.createjs;
    });
}

In the case of preloadjs specifically, just return the PreloadJS variable reference instead of createjs.

if (typeof define === "function" && define.amd) {
    define(function() {
        return window.createjs.PreloadJS;
    });
}

This, of course, still leaves createjs in the global namespace, though.

Upvotes: 2

Related Questions