Skip to content

Commit 917abcd

Browse files
committed
📝 Add a "Create an assets.json file" section to README
1 parent 9f50aac commit 917abcd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,34 @@ console.log(assetsLoader.stats.getMbps()); // e.g. 3.2
123123
assetsLoader.stats.log(); // e.g. Total loaded: 2.00mb time: 2.00s speed: 1.00mbps
124124
```
125125

126+
### Create an `assets.json` file
127+
Sometimes you may need to load a lot of assets. A simple solution for that is to generate an `assets.json` file listing all your assets. Here is a bash script to do that:
128+
129+
```bash
130+
#!/bin/bash
131+
132+
# Assign found results to an array
133+
# Source: https://stackoverflow.com/a/23357277/616095
134+
assets=()
135+
while IFS=read -r -d $'\0'; do assets+=("${REPLY//static\//}")
136+
137+
# Filter results (excluding static/fonts folder)
138+
# Source: http://www.liamdelahunty.com/tips/linux_find_exclude_multiple_directories.php
139+
done < <(find static \( -path static/fonts -o -name ".*" \) -prune -o -type f -print0)
140+
141+
# Format an array to JSON (require https://github.com/stedolan/jq)
142+
# Source: https://stackoverflow.com/a/26809318/616095
143+
printf '%s\n' "${assets[@]}" | jq -R . | jq -s . > dest/assets.json
144+
```
145+
146+
This script assumed that your assets are located in a `static/` folder and write the result to `dest/assets.json`. After running the script you just have to require your JSON file:
147+
148+
```javascript
149+
new assetsLoader({
150+
assets: require('dest/assets.json')
151+
})
152+
```
153+
126154
### Dev setup
127155

128156
To install dependencies:

0 commit comments

Comments
 (0)