I am writing an addon that wraps a third party library that uses globals and exporting them as es6 modules export default someGlobal
. The problem is that the consuming applications still sees the globals and complain during unit tests.
Is there a way I can insert these globals into the consuming applications .jshint file via a blurprint?
Is there a better way of exporting globals to es6 modules without actually modifying the third party code?
I found a way to achieve this using AMD modules.
// vendor/shims.js
window.DefaultGlobal = 'Hello';
window.AnotherGlobal = 'World';
//Shim as AMD module
define('YOUR_NAMESPACE', [], function() {
'use strict';
return {
default: DefaultGlobal, //same as 'export default var DefaultGlobal = 'Hello';'
AnotherGlobal: AnotherGlobal //same as 'export var AnotherGlobal = 'World'; '
};
});
Then you can access it via
import {DefaultGlobal, AnotherGlobal} from 'YOUR_NAMESPACE';