Added require.extensions and eslint rule. Fix #3598

This commit is contained in:
Richard Davey 2018-04-20 01:10:04 +01:00
parent 6299019838
commit 4018d6ab39
4 changed files with 21 additions and 0 deletions

View file

@ -51,6 +51,7 @@
"linebreak-style": [ "off" ],
"lines-around-comment": [ "error", { "beforeBlockComment": true, "afterBlockComment": false, "beforeLineComment": true, "afterLineComment": false, "allowBlockStart": true, "allowBlockEnd": false, "allowObjectStart": true, "allowArrayStart": true }],
"new-parens": "error",
"no-constant-condition": 0,
"no-array-constructor": "error",
"no-lonely-if": "error",
"no-mixed-spaces-and-tabs": "error",

View file

@ -9,6 +9,7 @@
### Updates
* 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)
* 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)
### Bug Fixes

View file

@ -4,6 +4,24 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
// For file loading of shader source outside of Webpack
// See: https://github.com/photonstorm/phaser/issues/3598
/* eslint-disable */
if (typeof SHADER_REQUIRE)
{
var fs = require('fs');
require.extensions['.frag'] = function (module, filename) {
module.exports = fs.readFileSync(filename, 'utf8');
};
require.extensions['.vert'] = function (module, filename) {
module.exports = fs.readFileSync(filename, 'utf8');
};
}
/* eslint-enable */
require('./polyfills');
var CONST = require('./const');

View file

@ -35,6 +35,7 @@ module.exports = {
plugins: [
new webpack.DefinePlugin({
"typeof SHADER_REQUIRE": JSON.stringify(false),
"typeof CANVAS_RENDERER": JSON.stringify(true),
"typeof WEBGL_RENDERER": JSON.stringify(true)
}),