Skip to content

Commit

Permalink
move preload bits under Electron only
Browse files Browse the repository at this point in the history
The `preload.js` generated script is included in browser builds, this
will cause issues for anyone trying to build a browser app.

This commit makes sure the Electron bits aren't used when building a
browser app.
  • Loading branch information
paul-marechal committed May 5, 2023
1 parent b6de884 commit ecf5dd6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ import { existsSync, readFileSync } from 'fs';

export class FrontendGenerator extends AbstractGenerator {

async generate(options: GeneratorOptions = {}): Promise<void> {
const frontendModules = this.pck.targetFrontendModules;
await this.write(this.pck.frontend('index.html'), this.compileIndexHtml(frontendModules));
await this.write(this.pck.frontend('index.js'), this.compileIndexJs(frontendModules));
await this.write(this.pck.frontend('preload.js'), this.compilePreloadJs());
async generate(options?: GeneratorOptions): Promise<void> {
await this.write(this.pck.frontend('index.html'), this.compileIndexHtml(this.pck.targetFrontendModules));
await this.write(this.pck.frontend('index.js'), this.compileIndexJs(this.pck.targetFrontendModules));
await this.write(this.pck.frontend('secondary-window.html'), this.compileSecondaryWindowHtml());
await this.write(this.pck.frontend('secondary-index.js'), this.compileSecondaryIndexJs(this.pck.secondaryWindowModules));
if (this.pck.isElectron()) {
const electronMainModules = this.pck.targetElectronMainModules;
await this.write(this.pck.frontend('electron-main.js'), this.compileElectronMain(electronMainModules));
await this.write(this.pck.frontend('electron-main.js'), this.compileElectronMain(this.pck.targetElectronMainModules));
await this.write(this.pck.frontend('preload.js'), this.compilePreloadJs());
}
}

Expand Down Expand Up @@ -90,8 +88,7 @@ self.MonacoEnvironment = {
getWorkerUrl: function (moduleId, label) {
return './editor.worker.js';
}
}
`)}
}`)}
const preloader = require('@theia/core/lib/browser/preloader');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ module.exports = [{
warnings: true,
children: true
}
}, {
}${this.pck.ifElectron(`, {
mode,
devtool: 'source-map',
entry: {
Expand All @@ -296,7 +296,7 @@ module.exports = [{
warnings: true,
children: true
}
}];`;
}`), ''}];`;
}

protected compileUserWebpackConfig(): string {
Expand Down

0 comments on commit ecf5dd6

Please sign in to comment.