I found the answer. I have to include it in the elements.xml as normally.
<Module Name="Files" Url="SiteAssets">
<File Path="test.js" Url="test.js" Type="GhostableInLibrary" ReplaceContent="TRUE" >
</File>
</Module>
Then reference the file in package-solution.json:
"assets": {
"elementManifests": [
"elements.xml"
],
"elementFiles":[
"test.js"
]
}
Finally, I have to extract the package using WinRar or something and include the js extension in the [Content_Types].xml (If the extension has already been here then you dont have to do this step. Right now it has .jpg, .pnp, .gif, .xml, .rels, .webpart, .htm, .aspx, .resx)
<Default Extension="js" ContentType="application/wsp"></Default>
<Default Extension="css" ContentType="text/stylesheet"></Default>
Trying to figure how to include js extension by default using gulp package-solution. Really hope MS will do this later instead of leaving out the .js (and .css) files.
Reference for [Content_Types].xml structure: https://docs.microsoft.com/en-us/visualstudio/extensibility/the-structure-of-the-content-types-dot-xml-file?view=vs-2022