Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
Webpack Define plugin replacement is evaluated but not injected

I have JS library foo which is being built with webpack which includes and builds the source code of the Phaser 3 library. Phaser 3 uses the define plugin to exclude parts of itself, for example replacing "typeof CANVAS_RENDERER" with false.

The issue I'm running into is this. when i include this block in my webpack config

    new webpack.DefinePlugin({
        "typeof CANVAS_RENDERER": JSON.stringify(false),
    }),

the kind of output i get is this

if (typeof WEBGL_RENDERER && typeof CANVAS_RENDERER)
{}

if (typeof WEBGL_RENDERER && !typeof CANVAS_RENDERER)
{
    WebGLRenderer = __webpack_require__(/*! ../renderer/webgl/WebGLRenderer */ "../node_modules/phaser/src/renderer/webgl/WebGLRenderer.js");

    //  Force the type to WebGL, regardless what was requested
    config.renderType = CONST.WEBGL;

    game.renderer = new WebGLRenderer(game);
}

Where typeof CANVAS_RENDERER has obviously been evalutated to false and as a result the function body has been optmised out but it didnt replace the original statement causing the code to go down the empty path when its run.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It seems that, if the plugin can't resolve each part of the if clause, in your case typeof WEBGL_RENDERER(since this is not defined in the new webpack.DefinePlugin), it doesn't resolve the rest.

With other words, if you define both in the plugin it should work:

new webpack.DefinePlugin({
    "typeof CANVAS_RENDERER": JSON.stringify(false),
    "typeof WEBGL_RENDERER": JSON.stringify(true),
}),

Atleast that solved the described problem, in my test setup.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!