diff --git a/apps/remix-ide/src/app/files/fileManager.js b/apps/remix-ide/src/app/files/fileManager.js index 10f89a4759..0ba692c32e 100644 --- a/apps/remix-ide/src/app/files/fileManager.js +++ b/apps/remix-ide/src/app/files/fileManager.js @@ -57,9 +57,10 @@ class FileManager extends Plugin { this.mode = mode } - async compileWithHardhat (cmd) { - console.log('Inside compileWithHardhat, calling hardhat compile using appManager') - return await this.appManager.call('hardhat', 'compile', cmd) + async compileWithHardhat (fileContent) { + const configFilePath = 'remixCompiler.config.js' + this.setFileContent(configFilePath, fileContent) + return await this.appManager.call('hardhat', 'compile', configFilePath) } limitPluginScope (path) { diff --git a/apps/remix-ide/src/app/tabs/compileTab/compileTab.js b/apps/remix-ide/src/app/tabs/compileTab/compileTab.js index 87cdc1b9a1..b4367cbb70 100644 --- a/apps/remix-ide/src/app/tabs/compileTab/compileTab.js +++ b/apps/remix-ide/src/app/tabs/compileTab/compileTab.js @@ -83,7 +83,18 @@ class CompileTab { console.log('mode is - ', this.fileManager.mode) if (this.fileManager.mode === 'localhost') { console.log('calling compilehardhat') - this.fileManager.compileWithHardhat('npx hardhat compile').then(console.log) + const { currentVersion, optimize, runs } = this.compiler.state + const fileContent = `module.exports = { + solidity: '${currentVersion.substring(0, currentVersion.indexOf('+commit'))}', + settings: { + optimizer: { + enabled: ${optimize}, + runs: ${runs} + } + } + } + ` + this.fileManager.compileWithHardhat(fileContent).then(console.log) } this.fileManager.saveCurrentFile() this.miscApi.clearAnnotations() diff --git a/libs/remixd/src/services/hardhatClient.ts b/libs/remixd/src/services/hardhatClient.ts index e2f58ee624..b03fa19cab 100644 --- a/libs/remixd/src/services/hardhatClient.ts +++ b/libs/remixd/src/services/hardhatClient.ts @@ -21,7 +21,8 @@ export class HardhatClient extends PluginClient { this.currentSharedFolder = currentSharedFolder } - compile (cmd: string) { + compile (configPath: string) { + const cmd = `npx hardhat compile --config ${configPath}` const options = { cwd: this.currentSharedFolder, shell: true } const child = spawn(cmd, options) let result = ''