How expose a exported function into global scope with babel and webpack

前端 未结 2 1402
悲&欢浪女
悲&欢浪女 2020-12-18 22:44

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         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-18 23:12

    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'
        }
    

提交回复
热议问题