OT: javascript / require / almond packaging issue

Hi,

  This is a bit off-topic, but I'm trying to package a project which

is based on Cesium, and is trying to use a similar AMD-style
modular structure, but I can’t seem to make it work. Maybe someone
with a lot more JS experience can immediately point out what’s
wrong with my approach.

I’m trying to use node,
r.js and almond to achieve this. The very same code / modules work
fine when looked at from a browser, and using a requirejs-style
loader.

The code in question is
here:

one can see a
‘source-version’ here:

  • this takes very long to download as it downloads hundreds of
    javascript files one by one. this is the very reason I want to
    pack all this into a single file.

the project is dependent on
dojo and Cesium: with
their source code being here:

I have the modules located
in my lib directory, side by side, with lib/Cesium, lib/dojo and
lib/OpenAviationMap (the latter being my code). I have a working
dojo-config, main.js, etc. that describe my module. this can be
successfully loaded by dojo’s requirejs (as visible on the
oam-WebGL URL above)

now, I’m trying to pack my
module, with all it’s dependencies (or without, both would be
fine) into a single file, using node, r.js and almond. for this,
I’ve created a build.js file in lib/OpenAviationMap (not in my
repo), which looks like:

({

baseUrl: '.',

name:

‘…/Cesium/ThirdParty/almond-0.2.5/almond.js’,

include: ['OpenAviationMap'],

insertRequire: ['OpenAviationMap'],

out: 'tmp/ize.js',

wrap : true,

useStrict : true,

optimizeCss : 'standard',

paths: {

    Cesium: '../Cesium/Source',

    dojo: '../dojo-release-1.9.1/dojo',

    dojox: '../dojo-release-1.9.1/dojox',

    ThirdParty:

‘…/Cesium/Source/ThirdParty’

}

})

and then I run the
following from within lib/OpenAviationMap:

mkdir tmp

…/Cesium/Tools/nodejs-0.6.17/linux/node
…/Cesium/ThirdParty/requirejs-2.1.6/r.js -o build.js
optimize=none

now this will create a
single file, tmp/ize.js, which looks fine, but when I try to use
it, my module, OpenAviationMap, is not reachable. I’m attempting
to use this in the following manner from within
lib/OpenAviationMap/tmp:

<title>Open Aviation Map WebGL

viewer

<script>

    var CESIUM_BASE_URL = './';

</script>

<script

src="./ize.js">

<!--<script

src="./Cesium.js">–>

<style>

  @import url(Widgets/Viewer/Viewer.css);

  @import url(../../../var/oam.css);

</style>
<div id="cesiumContainer"

class=“fullSize”>

<div

id=“loadingOverlay”>

Loading…

<div id="toolbar"></div>

<script>

var widget = new

OpenAviationMap.OamViewer({ container : ‘cesiumContainer’ });

</script>

interestingly, the very
same call works if I ‘requirejs’ the modules. moreover, with the
above I can actually make the Cesium dependency work, that is,
this works fine:

var cesiumWidget = new

Cesium.CesiumWidget(‘cesiumContainer’);

but my module is not
recognized.

I wonder what I’m doing
wrong.

Akos

I think you’re close to having something working. Comments inline.

thanks, I’ll give it a try…
I see…
I don’t, but, well, this is where my knowledge is short :slight_smile:
I have an OpenAviationMap ‘module’, which has a main.js, that
defines the components, etc.
please do, it would be of great help for me!
I seem to have this - that is, all works fine as long as I use
everything from ‘source’, via dojo. my impression was that the same
can be achieved after a ‘build’, with the very same ‘configuration’
that makes the ‘source’ setup work. but well, this does not seem to
be the case :frowning:
I really appreciate you looking into this
Akos