Skip to content

Commit 4018d6a

Browse files
committed
Added require.extensions and eslint rule. Fix phaserjs#3598
1 parent 6299019 commit 4018d6a

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"linebreak-style": [ "off" ],
5252
"lines-around-comment": [ "error", { "beforeBlockComment": true, "afterBlockComment": false, "beforeLineComment": true, "afterLineComment": false, "allowBlockStart": true, "allowBlockEnd": false, "allowObjectStart": true, "allowArrayStart": true }],
5353
"new-parens": "error",
54+
"no-constant-condition": 0,
5455
"no-array-constructor": "error",
5556
"no-lonely-if": "error",
5657
"no-mixed-spaces-and-tabs": "error",

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Updates
1010

1111
* We've swapped use of the Webpack DefinePlugin so instead of setting a global flag for the compilation of the Canvas and WebGL renderers, we now use a typeof check instead. This means you should now be able to ingest the Phaser source more easily outside of Webpack without having to define any global vars first (thanks @tgrajewski)
12+
* Under Webpack we still use the raw-loader to import our shader source, but outside of Webpack we now use `require.extensions` to load the shader source via fs. This should allow you to bundle Phaser with packages other than Webpack more easily (thanks @tgrajewski)
1213

1314
### Bug Fixes
1415

src/phaser.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
55
*/
66

7+
// For file loading of shader source outside of Webpack
8+
// See: https://github.com/photonstorm/phaser/issues/3598
9+
10+
/* eslint-disable */
11+
if (typeof SHADER_REQUIRE)
12+
{
13+
var fs = require('fs');
14+
15+
require.extensions['.frag'] = function (module, filename) {
16+
module.exports = fs.readFileSync(filename, 'utf8');
17+
};
18+
19+
require.extensions['.vert'] = function (module, filename) {
20+
module.exports = fs.readFileSync(filename, 'utf8');
21+
};
22+
}
23+
/* eslint-enable */
24+
725
require('./polyfills');
826

927
var CONST = require('./const');

webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = {
3535

3636
plugins: [
3737
new webpack.DefinePlugin({
38+
"typeof SHADER_REQUIRE": JSON.stringify(false),
3839
"typeof CANVAS_RENDERER": JSON.stringify(true),
3940
"typeof WEBGL_RENDERER": JSON.stringify(true)
4041
}),

0 commit comments

Comments
 (0)