How to use a plugin in Cocos Creator 3

I want use third party javascript within my cocos project.

In the editor I set the script as a plugin.

The problem I have is how to import and use this plugin?

I tried following in my script but it is not working

import Howler from '../../howler/howler.min';

Can you provide some help on how to use this script?

When you import a script as plugin, it will be loaded before the game scripts are loaded.
in your game script you can do something like this…

const Howler = (window as any).Howler  //assuming that the js you imported adds a Howler global variable in window. 

PS: This is the method i use to embed most of the libraries that i need and it works. But would love to hear if there is a better way.

1 Like