From 61921525f10c7672d2e2d1ad9c440ddc0435d2c9 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 24 Apr 2019 12:23:21 +0100 Subject: [PATCH] There is a new webpack config `FEATURE_SOUND` which is set to `true` by default, but if set to `false` it will exclude the Sound Manager and all of its systems into the build files. --- CHANGELOG.md | 1 + src/core/Game.js | 29 ++++++++++++++++++----------- src/phaser-arcade-physics.js | 6 +++++- src/phaser-core.js | 6 +++++- src/phaser.js | 6 +++++- webpack.config.js | 3 ++- webpack.dist.config.js | 3 ++- webpack.fb.config.js | 3 ++- webpack.fb.dist.config.js | 3 ++- 9 files changed, 42 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f21f09555..9b32b8fae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,7 @@ Notes: * `MultiScriptFile` is a new Loader FileType that allows you to load multiple script files into the document via the Phaser Loader, using the new `load.scripts` method. The difference between this and `load.script` is that you must pass an array of script file URLs to this method and they will be loaded in parallel but _processed_ (i.e. added to the document) in the exact order specified in the array. This allows you to load a bundle of scripts that have dependencies on each other. * `Key.getDuration` is a new method that will return the duration, in ms, that the Key has been held down for. If the Key isn't down it will return zero. * The `Container.setScrollFactor` method has a new optional argument `updateChildren`. If set, it will change the `scrollFactor` values of all the Container children as well as the Container. Fix #4466 #4475 (thanks @pinkkis @enriqueto) +* There is a new webpack config `FEATURE_SOUND` which is set to `true` by default, but if set to `false` it will exclude the Sound Manager and all of its systems into the build files. Fix #4428 (thanks @goldfire) ### Updates diff --git a/src/core/Game.js b/src/core/Game.js index fec90b51b..a9a16109f 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -23,12 +23,16 @@ var PluginCache = require('../plugins/PluginCache'); var PluginManager = require('../plugins/PluginManager'); var ScaleManager = require('../scale/ScaleManager'); var SceneManager = require('../scene/SceneManager'); -var SoundManagerCreator = require('../sound/SoundManagerCreator'); var TextureEvents = require('../textures/events'); var TextureManager = require('../textures/TextureManager'); var TimeStep = require('./TimeStep'); var VisibilityHandler = require('./VisibilityHandler'); +if (typeof FEATURE_SOUND) +{ + var SoundManagerCreator = require('../sound/SoundManagerCreator'); +} + if (typeof PLUGIN_FBINSTANT) { var FacebookInstantGamesPlugin = require('../../plugins/fbinstant/src/FacebookInstantGamesPlugin'); @@ -236,16 +240,19 @@ var Game = new Class({ */ this.scale = new ScaleManager(this, this.config); - /** - * An instance of the base Sound Manager. - * - * The Sound Manager is a global system responsible for the playback and updating of all audio in your game. - * - * @name Phaser.Game#sound - * @type {Phaser.Sound.BaseSoundManager} - * @since 3.0.0 - */ - this.sound = SoundManagerCreator.create(this); + if (typeof FEATURE_SOUND) + { + /** + * An instance of the base Sound Manager. + * + * The Sound Manager is a global system responsible for the playback and updating of all audio in your game. + * + * @name Phaser.Game#sound + * @type {Phaser.Sound.BaseSoundManager} + * @since 3.0.0 + */ + this.sound = SoundManagerCreator.create(this); + } /** * An instance of the Time Step. diff --git a/src/phaser-arcade-physics.js b/src/phaser-arcade-physics.js index aa2c76eb7..d79bc8a29 100644 --- a/src/phaser-arcade-physics.js +++ b/src/phaser-arcade-physics.js @@ -40,7 +40,6 @@ var Phaser = { Scale: require('./scale'), Scene: require('./scene/Scene'), Scenes: require('./scene'), - Sound: require('./sound'), Structs: require('./structs'), Textures: require('./textures'), Tilemaps: require('./tilemaps'), @@ -54,6 +53,11 @@ var Phaser = { Phaser = Extend(false, Phaser, CONST); +if (typeof FEATURE_SOUND) +{ + Phaser.Sound = require('./sound'); +} + // Export it module.exports = Phaser; diff --git a/src/phaser-core.js b/src/phaser-core.js index d5e290cc4..d0104f302 100644 --- a/src/phaser-core.js +++ b/src/phaser-core.js @@ -88,7 +88,6 @@ var Phaser = { Scale: require('./scale'), Scene: require('./scene/Scene'), Scenes: require('./scene'), - Sound: require('./sound'), Structs: require('./structs'), Textures: require('./textures'), Time: require('./time'), @@ -101,6 +100,11 @@ Phaser = Extend(false, Phaser, CONST); // Export it +if (typeof FEATURE_SOUND) +{ + Phaser.Sound = require('./sound'); +} + module.exports = Phaser; global.Phaser = Phaser; diff --git a/src/phaser.js b/src/phaser.js index a584024c9..84219bda7 100644 --- a/src/phaser.js +++ b/src/phaser.js @@ -39,7 +39,6 @@ var Phaser = { Scale: require('./scale'), Scene: require('./scene/Scene'), Scenes: require('./scene'), - Sound: require('./sound'), Structs: require('./structs'), Textures: require('./textures'), Tilemaps: require('./tilemaps'), @@ -51,6 +50,11 @@ var Phaser = { // Merge in the optional plugins +if (typeof FEATURE_SOUND) +{ + Phaser.Sound = require('./sound'); +} + if (typeof PLUGIN_CAMERA3D) { Phaser.Cameras.Sprite3D = require('../plugins/camera3d/src'); diff --git a/webpack.config.js b/webpack.config.js index 49f279177..9fbcccf2a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -31,7 +31,8 @@ module.exports = { "typeof WEBGL_RENDERER": JSON.stringify(true), "typeof EXPERIMENTAL": JSON.stringify(true), "typeof PLUGIN_CAMERA3D": JSON.stringify(false), - "typeof PLUGIN_FBINSTANT": JSON.stringify(false) + "typeof PLUGIN_FBINSTANT": JSON.stringify(false), + "typeof FEATURE_SOUND": JSON.stringify(true) }), { apply: (compiler) => { diff --git a/webpack.dist.config.js b/webpack.dist.config.js index a6795dc9d..82c6edee2 100644 --- a/webpack.dist.config.js +++ b/webpack.dist.config.js @@ -50,7 +50,8 @@ module.exports = { "typeof WEBGL_RENDERER": JSON.stringify(true), "typeof EXPERIMENTAL": JSON.stringify(false), "typeof PLUGIN_CAMERA3D": JSON.stringify(false), - "typeof PLUGIN_FBINSTANT": JSON.stringify(false) + "typeof PLUGIN_FBINSTANT": JSON.stringify(false), + "typeof FEATURE_SOUND": JSON.stringify(true) }), new CleanWebpackPlugin([ 'dist' ]) diff --git a/webpack.fb.config.js b/webpack.fb.config.js index 6dd6d0503..70b1cbcbf 100644 --- a/webpack.fb.config.js +++ b/webpack.fb.config.js @@ -31,7 +31,8 @@ module.exports = { "typeof WEBGL_RENDERER": JSON.stringify(true), "typeof EXPERIMENTAL": JSON.stringify(false), "typeof PLUGIN_CAMERA3D": JSON.stringify(false), - "typeof PLUGIN_FBINSTANT": JSON.stringify(true) + "typeof PLUGIN_FBINSTANT": JSON.stringify(true), + "typeof FEATURE_SOUND": JSON.stringify(true) }), { apply: (compiler) => { diff --git a/webpack.fb.dist.config.js b/webpack.fb.dist.config.js index 473a43970..fbeb82b5c 100644 --- a/webpack.fb.dist.config.js +++ b/webpack.fb.dist.config.js @@ -47,7 +47,8 @@ module.exports = { "typeof WEBGL_RENDERER": JSON.stringify(true), "typeof EXPERIMENTAL": JSON.stringify(false), "typeof PLUGIN_CAMERA3D": JSON.stringify(false), - "typeof PLUGIN_FBINSTANT": JSON.stringify(true) + "typeof PLUGIN_FBINSTANT": JSON.stringify(true), + "typeof FEATURE_SOUND": JSON.stringify(true) }) ] };