How can I compile my code with webpack and babel so that the exported function is available in the global scope.
So for example:
export function test
check out: https://github.com/webpack/docs/wiki/library-and-externals#examples
By setting the library output property to whatever name you want to wrap your globals would allow you to then call: YourLibrary.test();
module.exports = {
entry: ['./_js/script.js'],
output: {
library: 'YourLibrary',
path: __dirname,
filename: './build/script.js'
}
You can easily set a property on the global window
object. This will expose your object to the global scope.
function test() {
console.log('test');
}
window.test = test;
If you are developing a piece of code that does not represent a library but just some operations or functionalities to operate in global scope, I would prefer this method over to setting the library output property as mentioned in the accepted answer.