diff --git a/packages/plugin/webpack/src/WebpackConfig.ts b/packages/plugin/webpack/src/WebpackConfig.ts index 89c2874e78..aafd988bbe 100644 --- a/packages/plugin/webpack/src/WebpackConfig.ts +++ b/packages/plugin/webpack/src/WebpackConfig.ts @@ -97,7 +97,7 @@ export default class WebpackConfigGenerator { getDefines(inRendererDir = true) { const defines: { [key: string]: string; } = { - ASSET_RELOCATOR_BASE_DIR: this.assetRelocatorBaseDir(), + ASSET_RELOCATOR_BASE_DIR: this.assetRelocatorBaseDir(inRendererDir), }; if ( !this.pluginConfig.renderer.entryPoints diff --git a/packages/plugin/webpack/test/WebpackConfig_spec.ts b/packages/plugin/webpack/test/WebpackConfig_spec.ts index 55c2a6c6c9..c9cf251954 100644 --- a/packages/plugin/webpack/test/WebpackConfig_spec.ts +++ b/packages/plugin/webpack/test/WebpackConfig_spec.ts @@ -27,6 +27,68 @@ describe('WebpackConfigGenerator', () => { expect(() => generator.getDefines()).to.throw(/renderer.entryPoints.* has not been defined/); }); + it('sets the renderer asset relocator base dir in development', () => { + const config = { + renderer: { + entryPoints: [{ + name: 'hello', + js: 'foo.js', + }], + }, + } as WebpackPluginConfig; + const generator = new WebpackConfigGenerator(config, '/', false, 3000); + const defines = generator.getDefines(false); + + expect(defines.ASSET_RELOCATOR_BASE_DIR).to.equal(JSON.stringify(path.resolve('/.webpack', 'renderer', 'any_folder'))); + }); + + it('sets the renderer asset relocator base dir in production', () => { + const config = { + renderer: { + entryPoints: [{ + name: 'hello', + js: 'foo.js', + }], + }, + } as WebpackPluginConfig; + const generator = new WebpackConfigGenerator(config, '/', true, 3000); + const defines = generator.getDefines(false); + + // eslint-disable-next-line no-template-curly-in-string + expect(defines.ASSET_RELOCATOR_BASE_DIR).to.equal('process.resourcesPath + "/" + (__filename.includes(".asar") ? "app.asar" : "app") + "/.webpack/renderer/any_folder"'); + }); + + it('sets the main asset relocator base dir in development', () => { + const config = { + renderer: { + entryPoints: [{ + name: 'hello', + js: 'foo.js', + }], + }, + } as WebpackPluginConfig; + const generator = new WebpackConfigGenerator(config, '/', false, 3000); + const defines = generator.getDefines(true); + + expect(defines.ASSET_RELOCATOR_BASE_DIR).to.equal(JSON.stringify(path.resolve('/.webpack', 'main', '.'))); + }); + + it('sets the main asset relocator base dir in production', () => { + const config = { + renderer: { + entryPoints: [{ + name: 'hello', + js: 'foo.js', + }], + }, + } as WebpackPluginConfig; + const generator = new WebpackConfigGenerator(config, '/', true, 3000); + const defines = generator.getDefines(true); + + // eslint-disable-next-line no-template-curly-in-string + expect(defines.ASSET_RELOCATOR_BASE_DIR).to.equal('process.resourcesPath + "/" + (__filename.includes(".asar") ? "app.asar" : "app") + "/.webpack/main"'); + }); + it('sets the renderer entry point to a JS file in development', () => { const config = { renderer: {