load x3dom using requirejs - requirejs

I want to load the x3dom js library using requirejs. It's not working and produce the following error: TypeError: x3dom.gfx_webgl is not a function
I load the x3dom library like that:
require(['jquery-ui', 'x3dom'], function($, x3dom){
console.log(x3dom);
$('#test').html("hello");
});
You can see here that the loading of the libs seems to work (it's working for jquery).
I have a jsfiddle that shows the problem: http://jsfiddle.net/ayGR5/2/
If you load the script in the html pane (uncomment <!--<script src="http://www.x3dom.org/download/x3dom.js"></script>--> and comment lines 20-22 in the js pane), it's working.

It was a bug in x3dom. It's fixed now.
https://github.com/x3dom/x3dom/commit/354f1d0f24bf46a045364ac6b1f73f64984c4dc6

Related

How should a RequireJS transpilation plugin return its result?

Transpilation plugins like es6!, es!, and cs! are more complicated than simple plugins like text! because they return javascript modules that have their own dependencies.
Specifically, the code I've seen loads the specified file through XHR, transforms it, and then returns the result via a call like
onload.fromText("define(['foo', 'bar', ...");
That works fine for small test cases but throws a "Mismatched anonymous define() module" exception when running in my actual app. It's a race condition that happens when RequireJS is simultaneously processing a bunch of normal JS requires at the same time as evaluating a bunch of plugin requires.
Is this just a RequireJS bug, or is the plugin doing it wrong? Or, is it just not supported? Despite multiple transpilation plugin examples on the web, the RequireJS doc on that error says that
If you use the loader plugins or anonymous modules (modules that call define() with no string ID) but do not use the RequireJS optimizer to combine files together, this error can occur.

Require.js file is not supporting

I found the following issue while running my program. Here I send you the firebug console errors and the files which I included in my html page header part.If any one come to know what the issue is kindly tell me the solution.
Firebug console
Error: Module name "request" has not been loaded yet for context: _.
Use require([]) http://requirejs.org/docs/errors.html#notloaded
...c=c[b]});return c}function
C(b,c,d,e){c=Error(c+"\nhttp://requirejs.org/docs/err...
my code
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"
src="http://requirejs.org/docs/release/2.1.18/minified/require.js"
src="https://raw.githubusercontent.com/natevw/node-chargify/ad91cdec92f41d4045bb6e2189e5a04571576bcc/chargify.js"
you're not loading requirejs in the proper way. Should be like this :
<script data-main="js/your_main_file.js" src="js/require.js"></script>
Have a look at official doc for more info.

Debug CoffeeScript sources with node-inspector

I'm using CoffeeScript for a while to write Node.js programs. It's ok to debug with node-inspector if I compile the sources with Source Maps.
However, when I try to create a mixed Javascript/CoffeeScript app by using coffee-script/register:
#!/usr/bin/env node
require('coffee-script/register');
require('../src/client');
Then, node-inspector shows the compiled Javascript.
Is there how to see the actual *.coffee sources in node-inspector when I'm not explicity compiling it?
Disclaimer: I am a maintainer of Node Inspector
In order to see the actual *.coffee file in Node Inspector, you need to provide a source-map file describing how to map the transpiled javascript loaded inside Node/V8 runtime to you coffee-script source. Additionally, the filename of the transpiled javascript must be different from the original script name (AFAIK).
This is the trouble with require('coffee-script/register'): it converts the coffee-script source to the javascript source while keeping the same file name. In other words, the runtime (and Node Inspector) see that your *.coffee contain the transpiled javascript, thus it cannot display your coffee script for that very same filename. Also AFAIK, the coffee compiler does not emit any source map in this case.
I see two possible approaches to fix the problem:
Modify loadFile() in coffee-script/register:
emit a source map and save it to a file
pass a different filename to module._compile, e.g. script.coffee.js
Modify coffee-script/register to emit an embedded source map. Fix Chrome DevTools and/or Node Inspector to support embedded source maps.
References:
loadFile() in coffee-script/register
A Node Inspector issue discussing why coffee --nodejs --debug app.coffee does not work now: https://github.com/node-inspector/node-inspector/issues/224
A Node Inspector issue discussing inline source maps: https://github.com/node-inspector/node-inspector/issues/401

Using require.js to load non-AMD files and files with other than .js extension

Is there any clean way to load files with other than js extension and not AMD content?
I use the enforceDefine config to make sure my actual AMD code works while developing.
So far I've managed to put together a plugin that sets enforceDefine to false, so I can load 3rd party libraries like so: require(['noamd!handlebars']). That doesn't seem too much hacky to me but I'd like to know if there's a better way.
I'm currently testing the noext plugin and it does its job but also in a kind of a hacky way. I've noticed that it applies the noext parameter twice to the url (test.txt?noext=1&noext=1). I can live with that but optimally I'd like to git rid of all extra parameters. Can that be done?
To load files that aren't JS (such as .handlebars, .mustache) then the text plugin will suit your purposes.
To load normal js files you can use RequireJS as a script loader:
require(['full/path/to/file.js'], function(){
// Fired when file is loaded but if non AMD
// no value will be passed to this function
});
If you would like to treat the non-AMD file as a module, then you can use the shim config to implement it.
you can append a ?MEH=BLAH to the end to stop the .js appending
eg
requirejs.config({
paths: {
"dynamicstripconfig": "../php/domain/config.php?dynamic=1"
}
});
Additionally there a plugin for that as well, but doesn't support paths -> https://github.com/millermedeiros/requirejs-plugins
Added a issue with fix for path support -> https://github.com/millermedeiros/requirejs-plugins/issues/47
If your file isn't actually a dynamic js file then use the text plugin -> https://github.com/millermedeiros/requirejs-plugins

NodeJS & mustache: how to get partials working?

I want to use mustache with node, but for some reason partials won't work: I've created 2 files, app.js and test.mustache, both in the same directory. Using a package.json file and npm I've installed the latest version of mustache for this project. The files look like this:
app.js:
var mus = require('mustache');
console.log(mus.render('test.mustache: {{>test}}'));
test.mustache:
This is a test
If I run node app.js I expect to get the following output: test.mustache: This is a test, but instead I just get: test.mustache:.
Other mustache tags do work as expected, and even the vows test of mustache doesn't report any errors.
What should I do to get this to work correctly?
Using node-inspector I've debugged the above application with Mustache. It turns out that Mustache doesn't automatically include the partial files, in contrary to what the manual implies (scroll down to partials). Instead you'll always need to provide the partials manually as the third argument to the render method.
FYI, this version of Consolidate.js supports partials: https://github.com/simov/consolidate.js
Consolidate makes it easy to use many templating engines inside Express.js

Resources