Code generator for embedding directories with files into executables
The
$embed_file
File embedding in V is done at compile time, and unfortunately there is no way
to dynamically embed arbitrary files into an application. The
embedfs
.v
v install --git https://github.com/gechandesu/embedfs
Usage
For example you have following file structure:
v.mod
src/
main.v
assets/
css/style.css
js/app.js
Lets embed the
assets
Create
embed_assets.vsh
#!/usr/bin/env -S v
import embedfs
chdir('src')!
assets := embedfs.CodeGenerator{
path: 'assets'
}
write_file('assets_generated.v', assets.generate())!
Run it:
v run embed_assets.vsh
Now you have
src/assets_generated.v
embedfs
src/main.v
module main
fn main() {
style := embedfs.files['assets/css/style.css']!
println(style.data.to_string())
}