Skip to content

Instantly share code, notes, and snippets.

@cuth
Last active January 15, 2016 20:22
Show Gist options
  • Save cuth/aaea4769d738656bd9d9 to your computer and use it in GitHub Desktop.
Save cuth/aaea4769d738656bd9d9 to your computer and use it in GitHub Desktop.
Disable AMD when requiring a file.
const safeRequire = require('./safe-require');
const umdStyleMod = safeRequire('umd-style-mod', () => require('umd-style-mod'));
'use strict';
/* global define */
const cache = {};
module.exports = function (name, req) {
if (cache.hasOwnProperty(name)) {
return cache[name];
}
if (typeof define === 'function' && define.amd) {
const temp = define.amd;
define.amd = false;
cache[name] = req();
define.amd = temp;
} else {
cache[name] = req();
}
return cache[name];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment