jonjonjon
4 months ago
1252
3
Mix

Laravel Mix - expose function to be used in browser

Posted 4 months ago by jonjonjon

I have a typescript file that I would like to build with mix, and then use it in another page as a javascript library. i.e:

<script type="module" src="/js/index.js">
    console.log("test");
</script>

How can I achieve this with mix?

I was able to use mix.ts('resources/index.ts', 'public/js') to create the file, but all attempts to use the functions inside the file:

i.e:

    import getInfo from '/js/index.js'

    import {getInfo} from '/js/index.js'

all result in similar errors: The requested module '/js/index.js' does not provide an export named 'default', The requested module '/js/index.js' does not provide an export named 'getInfo'

When I look in js/index.js I can actually see the methods that I want to use, so I know they were somewhat exported. But I'm not sure how I can actually use the function.

I've checked the window variable and the functions are also not there.

Thank you

Please sign in or create an account to participate in this conversation.