Convert to CommonJS-style require syntax, but produce current syntax as build output
See original GitHub issueRequireJS and most other AMD loaders support a so-called “CommonJS-style” syntax for requiring in dependencies: http://requirejs.org/docs/commonjs.html
Essentially,
define(function (require) {
var foo = require('foo');
var bar = require('bar');
//etc
});
Not only is this syntax far easier to read, but it would let us more easily detect unused dependencies, since they become unused local variables, rather than unused parameters. The problem with this syntax is that some build tools, notably the Dojo build system, don’t properly detect dependencies when modules are required using this syntax (bug).
We can use the more convenient syntax directly for development and testing, where we load in individual modules asynchronously directly from the source files, and then as part of our build process produce versions of the modules with the dependencies listed in the more widely-supported conventional manner. These would be the set of modules that we ship with releases, and build Dojo-based applications against.
Either by solely adding the dependency array:
define(['require', 'foo', 'bar'], function (require) {
var foo = require('foo');
var bar = require('bar');
//etc
});
(once the dependencies are declared explicitly, we can require them synchronously knowing that they will already be available)
Or, by adjusting the code to even more closely match our current style:
define(['require', 'foo', 'bar'], function (require, foo, bar) {
//etc
});
The RequireJS loader has a regex to find require('')
calls, but I think it may be better in our case to be more specific and look for larger var a = require('b');
statements, since in the future I would also like to start moving towards dynamically requiring materials, visualizers, etc. to make it more feasible to produce custom builds that exclude unused code. (#351)
Issue Analytics
- State:
- Created 10 years ago
- Comments:13 (10 by maintainers)
Top GitHub Comments
@jpierson The discussion for ES6 modules has been in https://github.com/AnalyticalGraphicsInc/cesium/issues/2524
@mramato, where are the plans to move to ES6 modules being tracked? As far as I can tell from some brief searching this hasn’t been completed in the 3 years since this issue was closed and I was unable to find any other tracking open tracking issue covering the movement to ES modules specifically.