Skip to content

Commit ed82918

Browse files
author
Matt Colman
committed
fix demo
1 parent 8ed1b0a commit ed82918

File tree

2 files changed

+88
-36
lines changed

2 files changed

+88
-36
lines changed

demo/states/LoaderState.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ export default class extends Phaser.State {
99
}
1010

1111
create () {
12-
this.manifestLoader = this.game.plugins.add(ManifestLoader)
12+
const req = require.context(
13+
'../../assets',
14+
true,
15+
/.*\.png|json|ttf|woff|woff2|xml|mp3|jpg|jpeg$/
16+
)
17+
this.manifestLoader = this.game.plugins.add(ManifestLoader, req)
1318
// What I like about the ManifestLoader is that `loadManifest` returns
1419
// a promise, so we have more control over it.
1520
Promise.all([
@@ -22,9 +27,15 @@ export default class extends Phaser.State {
2227

2328
startLoadingAnimation () {
2429
return new Promise((resolve, reject) => {
25-
const spinner = this.add.image(this.world.centerX, this.world.centerY, 'loader')
30+
const spinner = this.add.image(
31+
this.world.centerX,
32+
this.world.centerY,
33+
'loader'
34+
)
2635
spinner.anchor.set(0.5)
27-
this.add.tween(spinner).to({angle: 360}, 1000, 'Linear', true, 0, -1, false)
36+
this.add
37+
.tween(spinner)
38+
.to({ angle: 360 }, 1000, 'Linear', true, 0, -1, false)
2839
// If the assets are found in the browser cache they will probably load in < 1 second
2940
// typically causing a flash where the user sees the loading animation for a split second
3041
// Here we ensure the loading will be visible for at least 2 seconds so there is no flash

webpack.config.js

+74-33
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ console.log('isProd', isProd)
1313

1414
module.exports = {
1515
entry: {
16-
app: [
17-
'babel-polyfill',
18-
path.resolve(__dirname, 'demo/main.js')
19-
],
16+
app: ['babel-polyfill', path.resolve(__dirname, 'demo/main.js')],
2017
vendor: ['pixi', 'p2', 'phaser', 'webfontloader']
2118
},
2219
devtool: 'cheap-source-map',
@@ -28,40 +25,84 @@ module.exports = {
2825
},
2926
watch: !isProd,
3027
plugins: [
31-
new webpack.optimize.CommonsChunkPlugin({ name: 'vendor'/* chunkName= */, filename: 'vendor.bundle.js'/* filename= */ }),
28+
new webpack.optimize.CommonsChunkPlugin({
29+
name: 'vendor' /* chunkName= */,
30+
filename: 'vendor.bundle.js' /* filename= */
31+
}),
3232
new webpack.ProvidePlugin({
33-
Promise: 'imports-loader?this=>global!exports-loader?global.Promise!es6-promise'
33+
Promise:
34+
'imports-loader?this=>global!exports-loader?global.Promise!es6-promise'
3435
})
35-
].concat(!isProd ? [
36-
new BrowserSyncPlugin({
37-
host: process.env.IP || 'localhost',
38-
port: process.env.PORT || 3000,
39-
server: {
40-
baseDir: ['./']
41-
}
42-
})
43-
] : []),
36+
].concat(
37+
!isProd
38+
? [
39+
new BrowserSyncPlugin({
40+
host: process.env.IP || 'localhost',
41+
port: process.env.PORT || 3000,
42+
server: {
43+
baseDir: ['./']
44+
}
45+
})
46+
]
47+
: []
48+
),
4449
module: {
4550
rules: [
46-
{ test: /\.js$/, use: ['babel-loader'], include: [path.join(__dirname, 'src'), path.join(__dirname, 'demo')] },
51+
{
52+
test: /\.js$/,
53+
use: ['babel-loader'],
54+
include: [path.join(__dirname, 'src'), path.join(__dirname, 'demo')]
55+
},
4756
{ test: /pixi\.js/, use: ['expose-loader?PIXI'] },
4857
{ test: /phaser-split\.js$/, use: ['expose-loader?Phaser'] },
4958
{ test: /p2\.js/, use: ['expose-loader?p2'] },
50-
{ test: /\.css$/,
51-
use: [ 'style-loader', 'css-loader' ] },
52-
{ test: /\.woff|\.woff2|\.svg|.eot|\.ttf/,
53-
use: 'url-loader?prefix=font/&limit=10000&name=[name]-[hash].[ext]' },
54-
{ test: /\.mp3$/,
55-
use: 'file-loader?hash=sha512&digest=hex&name=[name]-[hash].[ext]' },
56-
{ test: /.*\.(gif|png|svg)$/i,
59+
{
60+
test: /\.css$/,
61+
use: ['style-loader', 'css-loader']
62+
},
63+
{
64+
test: /\.woff|\.woff2|\.svg|.eot|\.ttf/,
65+
use: 'url-loader?prefix=font/&limit=10000&name=[name]-[hash].[ext]'
66+
},
67+
{
68+
test: /\.mp3$/,
69+
use: 'file-loader?hash=sha512&digest=hex&name=[name]-[hash].[ext]'
70+
},
71+
{
72+
test: /\.(gif|png|svg)$/i,
5773
use: [
58-
'file-loader?hash=sha512&digest=hex&name=[name]-[hash].[ext]',
59-
'image-webpack-loader?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}}'
60-
]},
61-
{ test: /\.(jpg)$/,
62-
use: 'url-loader?limit=25000&name=[name]-[hash].[ext]'},
63-
{ test: /\.xml$/,
64-
use: 'file-loader?hash=sha512&digest=hex&name=[name]-[hash].[ext]'}
74+
{
75+
loader: 'file-loader',
76+
options: {
77+
hash: 'sha512',
78+
digest: 'hex',
79+
name: '[hash].[ext]'
80+
}
81+
},
82+
{
83+
loader: 'image-webpack-loader',
84+
options: {
85+
mozjpeg: {
86+
progressive: true
87+
},
88+
optipng: {
89+
optimizationLevel: 7
90+
},
91+
gifsicle: {
92+
interlaced: false
93+
}
94+
}
95+
}
96+
]
97+
},
98+
{
99+
test: /\.(jpg)$/,
100+
use: 'url-loader?limit=25000&name=[name]-[hash].[ext]'
101+
},
102+
{
103+
test: /\.xml$/,
104+
use: 'file-loader?hash=sha512&digest=hex&name=[name]-[hash].[ext]'
105+
}
65106
]
66107
},
67108
node: {
@@ -71,9 +112,9 @@ module.exports = {
71112
},
72113
resolve: {
73114
alias: {
74-
'phaser': phaser,
75-
'pixi': pixi,
76-
'p2': p2,
115+
phaser: phaser,
116+
pixi: pixi,
117+
p2: p2,
77118
assets: path.join(__dirname, 'assets')
78119
}
79120
}

0 commit comments

Comments
 (0)