forge icon indicating copy to clipboard operation
forge copied to clipboard

*_PRELOAD_WEBPACK_ENTRY is not correct under product mode got from renderer process

Open zhy1440 opened this issue 3 years ago • 0 comments

Pre-flight checklist

  • [X] I have read the contribution documentation for this project.
  • [X] I agree to follow the code of conduct that this project uses.
  • [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

6.0.0-beta.64

Electron version

v19.0.8

Operating system

Windows 10 (1826)

Last known working Electron Forge version

No response

Expected behavior

_PRELOAD_WEBPACK_ENTRY is not correct under product mode got from renderer process. It will get _...webpack*renderer*renderer*{entry_name}\preload.js_. The root cause is in WebpackConfig.ts line 92. return `require('path').resolve(__dirname, '../renderer', '${entryPoint.name}', 'preload.js')`;

  getPreloadDefine(entryPoint: WebpackPluginEntryPoint): string {
    if (entryPoint.preload) {
      if (this.isProd) {
        return `require('path').resolve(__dirname, '../renderer', '${entryPoint.name}', 'preload.js')`;
      }
      return `'${path.resolve(this.webpackDir, 'renderer', entryPoint.name, 'preload.js').replace(/\\/g, '\\\\')}'`;
    }
    // If this entry-point has no configured preload script just map this constant to `undefined`
    // so that any code using it still works.  This makes quick-start / docs simpler./*  */
    return 'undefined';
  }

For the solution, please reference to line 75 return `\`file://$\{require('path').resolve(__dirname, '..', '${inRendererDir ? 'renderer' : '.'}', '${entryPoint.name}', '${basename}')}\``;

Actual behavior

Cannot get right path in renderer process.

Steps to reproduce

Print the preload entry in renderer process. eg. console.log(ELECTRON_TABS_PRELOAD_WEBPACK_ENTRY);

Additional information

No response

zhy1440 avatar Jul 19 '22 07:07 zhy1440