Skip to content

Commit 3c9dc08

Browse files
author
Matt Colman
committed
change to file-loader for json files
v3.0.0
1 parent 4360eee commit 3c9dc08

File tree

5 files changed

+70
-8
lines changed

5 files changed

+70
-8
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 3.0.0
4+
- change loading of spritesheet json files to expect a json url rather than a json object. (This requires the use of [file-loader](https://github.com/webpack-contrib/file-loader) for json files in your webpack config)
5+
This change was made to support other libraries such as dragonbones. I also think it makes more sense to lazy load json files rather than include them in the main bundle (especially if you're using dragonbones!).
6+
37
## 2.1.0
48
- support m4a and wav (thanks @BernsteinA)
59
- allow loading multiple audio files and let browser choose the best (thanks @BernsteinA)

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,64 @@ Create an assets directory with subdirectories for the asset types that you will
9797
/fonts (webfonts)
9898
/bitmap_fonts (png + xml)
9999
```
100+
### Webpack config
101+
Expects all assets to be in the form of a url. The main gotcha is that webpack by default will bundle your spritesheet json files into the main bundle which is not what we want. So make sure you use file-loader for json files. Example config:
102+
```
103+
rules: [
104+
{
105+
test: /\.json$/,
106+
use: 'file-loader',
107+
},
108+
{
109+
test: /\.woff|\.woff2|\.svg|.eot|\.ttf/,
110+
use: 'url-loader?prefix=font/&limit=10000&name=[name]-[hash].[ext]',
111+
},
112+
{
113+
test: /\.mp3$/,
114+
use: 'file-loader?hash=sha512&digest=hex&name=[name]-[hash].[ext]',
115+
},
116+
{
117+
test: /\.(png)$/i,
118+
use: [
119+
{
120+
loader: 'file-loader',
121+
options: {
122+
hash: 'sha512',
123+
digest: 'hex',
124+
name: '[name]-[hash].[ext]',
125+
},
126+
},
127+
{
128+
loader: 'image-webpack-loader',
129+
options: {
130+
progressive: true,
131+
optipng: {
132+
optimizationLevel: 7,
133+
},
134+
gifsicle: {
135+
interlaced: false,
136+
},
137+
},
138+
},
139+
],
140+
},
141+
{
142+
test: /\.jpg$/,
143+
use: [
144+
{
145+
loader: 'url-loader?hash=sha512&digest=hex&name=[name]-[hash].[ext]',
146+
options: {
147+
limit: 25000,
148+
},
149+
},
150+
],
151+
},
152+
{
153+
test: /\.xml$/,
154+
use: 'file-loader?hash=sha512&digest=hex&name=[name]-[hash].[ext]',
155+
},
156+
]
157+
```
100158

101159
## Usage
102160
### Basic

lib/AssetLoader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var AssetLoader = function (_Plugin) {
109109

110110
if (!imageUrl) warn('spriteSheet image', key);
111111
if (!jsonUrl) warn('spriteSheet json', key);
112-
this.game.load.atlasJSONArray(key, imageUrl, null, jsonUrl);
112+
this.game.load.atlasJSONArray(key, imageUrl, jsonUrl);
113113
}
114114
}, {
115115
key: 'loadImage',

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "phaser-manifest-loader",
3-
"version": "2.1.0",
3+
"version": "3.0.0",
44
"description": "Easily load assets into your Phaser game using a simple manifest",
55
"author": "matt colman <[email protected]>",
66
"main": "lib/index.js",

src/AssetLoader.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@ export default class AssetLoader extends Plugin {
3939

4040
loadAudio (key) {
4141
const urls = []
42-
42+
4343
try {
4444
urls.push(this.req(`./audio/${key}.mp3`))
4545
} catch (e) {}
46-
46+
4747
try {
4848
urls.push(this.req(`./audio/${key}.ogg`))
4949
} catch (e) {}
50-
50+
5151
try {
5252
urls.push(this.req(`./audio/${key}.m4a`))
5353
} catch (e) {}
54-
54+
5555
try {
5656
urls.push(this.req(`./audio/${key}.wav`))
5757
} catch (e) {}
58-
58+
5959
if (urls.length === 0) {
6060
warn('audio', key)
6161
} else {
@@ -75,7 +75,7 @@ export default class AssetLoader extends Plugin {
7575

7676
if (!imageUrl) warn('spriteSheet image', key)
7777
if (!jsonUrl) warn('spriteSheet json', key)
78-
this.game.load.atlasJSONArray(key, imageUrl, null, jsonUrl)
78+
this.game.load.atlasJSONArray(key, imageUrl, jsonUrl)
7979
}
8080

8181
loadImage (key, assetPostfix) {

0 commit comments

Comments
 (0)