Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help using with requirejs #18

Closed
dunko opened this issue Jul 26, 2015 · 4 comments
Closed

help using with requirejs #18

dunko opened this issue Jul 26, 2015 · 4 comments

Comments

@dunko
Copy link

dunko commented Jul 26, 2015

Hi there,
I was wondering if anyone could provide me with some newbie instructions, or set me in the right direction using this library with requirejs.

I'm using your example as a main.js and getting an 'amdefine' not defined, if I comment out that if statement, I"m getting a 'define not defined' reference error.

Any help you can offer would be greatly appreciated, I'm just starting out in my first dev job so like I said I'm very much a coming to terms with some understanding JS concepts.

I've been trying this a couple of ways, one using amdefine as per http://requirejs.org/docs/node.html and the other using the define syntax as described under 'Usage' on https://github.com/shashwatak/satellite-js

Any help greatly appreciated
thanks
Duncan

var requirejs = require('requirejs');

if (typeof define !== 'function') {
var define = require('amdefine')(module,require);
}

define(function(require) {
var dep = require('dependency');

//The value returned from the function is
//    //used as the module export visible to Node.
 return function () {};

});

requirejs.config({
//Pass the top-level main.js/index.js require
// //function to requirejs so that node modules
// //are loaded relative to the top-level JS file.
baseUrl: __dirname,
nodeRequire: require,
});

      requirejs(['foo', 'bar'],
      function   (foo,   bar) {
             //foo and bar are loaded according to requirejs
                //config, but if not found, then node's require
                  //is used to load the module.
 });

module.exports = function () {};
// Sample TLE
var tleLine1 = '1 25544U 98067A 13149.87225694 .00009369 00000-0 16828-3 0 9031',
tleLine2 = '2 25544 051.6485 199.1576 0010128 012.7275 352.5669 15.50581403831869';

// Initialize a satellite record
define(['satellite.js/dist/satellite.min.js'], function(satellite) {
var satrec = satellite.twoline2satrec(tleLine1, tleLine2);
});

@chk1
Copy link

chk1 commented Sep 12, 2015

I got it working with just this code:

<script type="text/javascript" src="scripts/require.js"></script>
<script>
require([
  "scripts/satellite.js/dist/satellite",
], function(satellite){
  console.log(satellite);
  /* your satellite code here */
});
</script>

The folder structure is as follows:

index.html <-- above code in here
scripts/require.js
scripts/satellite.js/dist/satellite.js

Another unrelated note:

This works with Esri's JS API too, just make sure to put the "dojo/domReady!" dependency last or else you will receive errors like TypeError: satellite.twoline2satrec is not a function and console.log(satellite) will result in an HTMLDocument object rather than the intended one.

@thkruz
Copy link
Collaborator

thkruz commented Sep 16, 2018

Given how old this issue is, can we close it?

@dunko
Copy link
Author

dunko commented Sep 16, 2018 via email

@ezze
Copy link
Collaborator

ezze commented Sep 17, 2018

I created a repo showing a basic usage with Require.js.
Thanks for contribution.

@ezze ezze closed this as completed Sep 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants