I use data URI, base64 to add images and videos to my game, but I found that if I want to make a game with multiple videos, each video will be over 500 lines of code, so is there anything Good method? It is recommended to handle this type of file, what I really did was make a Mixin file and make multiple functions that return base64.
export default{ stage1(){ return "data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAFkAdtZGF0AAADAAYF///........." }, stage2(){ return "data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAFkAdtZGF0AAADAAYF///........." }, }
I recommend using a bundler like (webpack, parcel, rollup, browserify, etc.) where you can program in multiple files and the bundler will merge all the files before deploying into a file (and minify it) .
Using a bundler like webpack you can create a json file containing all the dataurls, for example:
In application script:
And in the application file you can import the json file and it will be integrated into the bundler build action. And create a single file that contains all the files of the application.
For more information about webpack and how to set up your project Check the documentation. It's too long to describe it in an answer, and there are already good articles/videos on it. (but you can also use any other bundler)
My answer points you in the right direction.
renew:
A small demo project (if you have node and npm installed) :
Use npmInstall these packages
Create a basic configuration file for webpack:
Here is the demo application code:
The demo project structure is as follows:
It will only create an output html file, all other files will be inlined.