rpflorence/publisher.js — Issue #5: Errors as AMD module with RequireJS Optimization
Author: mjtognetti
Created: 2011-12-06 19:08:22+00:00
State: open

When run as an AMD module and optimized by @jburke 's RequireJS, Publisher fails to be defined as a module. Instead an empty ```define('publisher', function(){})``` is produced, breaking any code Publisher-dependent code.

Quoting @jburke from https://github.com/ded/morpheus/issues/19 , in which an identical problem and its solution are discussed:

>The issue is that the requirejs optimizer uses an AST to find define() calls that look like AMD define calls. Since define(definition) is a bit too generic it skips it and puts in an empty module for the 'morpheus' name.

>Two possible easy fixes:

>1) Use a function literal:

>```if (typeof define == 'function') define(function(){return definition()})```

>2) Or just pass name to the function:

>```if (typeof define == 'function') define(name, definition)```