문제

Disclaimer: I'm a total AMD n00b.

I have a project that I'm trying to convert over to AMD. Originally, all the code was in a single file. I was able to split functional units into their own modules, but they were all in the same file. I decided to split them into AMD modules and then combine everything using the optimizer. A helpful contributor already converted my module into UMD and so it seemed to be pretty simple to move everything over.

My main file (i.e., my library that I'm writing) looks like this:

(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(factory);
    } else {
        // Browser globals
        root.regula = factory();
    }
}(this, function () {
    define(
        [
            "utils/MapUtils",
            "utils/DOMUtils",
            "service/BindingService",
            "service/ExceptionService",
            "service/ConstraintService",
            "service/ValidationService",
            "service/GroupService"
        ],
        function (MapUtils, DOMUtils, BindingService, ExceptionService, ConstraintService, ValidationService, GroupService) {

            ...
            ...

            return {
                configure: configure,
                bind: bind,
                unbind: unbind,
                validate: validate,
                custom: custom,
                compound: compound,
                override: override,
                Constraint: ConstraintService.Constraint,
                Group: GroupService.Group,
                DateFormat: DateFormat,
                Exception: ExceptionService.Exception
            };
        }
    );
}));

And my directory structure is as follows:

regula
├── amdtest.html
├── dist
│   └── src
└── src
    ├── build.js
    ├── domain
    │   └── CompositionGraph.js
    ├── jquery.regula.js
    ├── lib
    │   ├── closure
    │   │   └── compiler.jar
    │   ├── require
    │   │   ├── require.js
    │   │   └── r.js
    │   └── rhino
    │       └── js.jar
    ├── parser
    │   └── Parser.js
    ├── regula.js
    ├── service
    │   ├── BindingService.js
    │   ├── ConstraintService.js
    │   ├── ExceptionService.js
    │   ├── GroupService.js
    │   └── ValidationService.js
    └── utils
        ├── ArrayUtils.js
        ├── DOMUtils.js
        └── MapUtils.js

My build.js is:

({
    appDir: "../",
    baseUrl: "src",
    dir: "../dist",
    modules: [{
        name: "regula"
    }]
})

I'm using Rhino and Closure to run the optimizer as follows:

java -cp lib/rhino/js.jar:lib/closure/compiler.jar org.mozilla.javascript.tools.shell.Main lib/require/r.js build.js

Unfortunately this doesn't produce any sort of output or error. All Javascript modules that are referenced in regula.js are AMD modules as well. Any idea what I'm doing wrong? I can post more information if that would help. I didn't want to do a huge dump of random information because as I mentioned before, I'm a complete newbie when it comes to AMD and so I'm not entirely sure what is relevant.

도움이 되었습니까?

해결책

You forgot to pass the -o flag to run r.js in the optimizer mode! More details in the official docs

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top