dojo/loader

Not declare a global require when not running in a browser

kitsonk opened this issue · 1 comments

From a side comment from @taoqf in #68...

We might want to consider not declaring a default global require when the loader loads in a non-browser environment. RequireJS does not do this, meaning that loader can be required in and outer require() will be named whatever anyone wishes it to be. This would eliminate the global require definition from the typings as well, which would reduce conflicts with other typings (namely NodeJS) that also declare a global require.

I believe the loader already works like this....

The following snippet works as you would expect, importing dojo's require as well as using the node require.

import { RootRequire } from 'dojo-interfaces/loader';

const loader: RootRequire = require('dojo-loader');

// require still uses node's loader
const anotherModule = require('./another-module');

// loader contains dojo require
loader(['./another-module'], (anotherModule) => {
    console.log('loaded');
});

Also, dojo loader does set global require, but it does not actually override the node require because that's not global (it's sort of a like a context require). The require types are already not global, they are wrapped in a DojoLoader namespace.

So if there is anything to do here, I can remove the part that is setting a global require object, but I don't think it is causing any harm?