Electron Js-Require()不';不要加载javascript文件

Electron Js-Require()不';不要加载javascript文件,javascript,electron,Javascript,Electron,嗨,我是electron js的新手,我正在尝试制作一个无框窗口,它有一个自定义的顶部栏,我可以用于窗口最小化、最大化和关闭 我有一个单独的.js文件用于windows最小化、关闭等函数,名为renderer.js。它与我的index.js位于同一目录中。像这样: 我在index.html文件上调用函数require('renderer.js') 下面是我的index.html的代码 <!DOCTYPE html> <html> <head> &

嗨,我是electron js的新手,我正在尝试制作一个无框窗口,它有一个自定义的顶部栏,我可以用于窗口最小化、最大化和关闭

我有一个单独的.js文件用于windows最小化、关闭等函数,名为
renderer.js
。它与我的
index.js
位于同一目录中。像这样:

我在
index.html
文件上调用函数
require('renderer.js')

下面是我的index.html的代码

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Hello World!</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>

    <header id="titlebar">
      <div id="drag-region">

        <div id="window-title">
          <span>Electron quick start</span>
        </div>

        <div id="window-controls">

          <div class="button" id="min-button">
            <img class="icon" srcset="icons/min-w-10.png 1x, icons/min-w-12.png 1.25x, icons/min-w-15.png 1.5x, icons/min-w-15.png 1.75x, icons/min-w-20.png 2x, icons/min-w-20.png 2.25x, icons/min-w-24.png 2.5x, icons/min-w-30.png 3x, icons/min-w-30.png 3.5x" draggable="false" />
          </div>
          <div class="button" id="max-button">
            <img class="icon" srcset="icons/max-w-10.png 1x, icons/max-w-12.png 1.25x, icons/max-w-15.png 1.5x, icons/max-w-15.png 1.75x, icons/max-w-20.png 2x, icons/max-w-20.png 2.25x, icons/max-w-24.png 2.5x, icons/max-w-30.png 3x, icons/max-w-30.png 3.5x" draggable="false" />
          </div>
          <div class="button" id="restore-button">
            <img class="icon" srcset="icons/restore-w-10.png 1x, icons/restore-w-12.png 1.25x, icons/restore-w-15.png 1.5x, icons/restore-w-15.png 1.75x, icons/restore-w-20.png 2x, icons/restore-w-20.png 2.25x, icons/restore-w-24.png 2.5x, icons/restore-w-30.png 3x, icons/restore-w-30.png 3.5x" draggable="false" />
          </div>
          <div class="button" id="close-button">
            <img class="icon" srcset="icons/close-w-10.png 1x, icons/close-w-12.png 1.25x, icons/close-w-15.png 1.5x, icons/close-w-15.png 1.75x, icons/close-w-20.png 2x, icons/close-w-20.png 2.25x, icons/close-w-24.png 2.5x, icons/close-w-30.png 3x, icons/close-w-30.png 3.5x" draggable="false" />
          </div>

        </div>
      </div>
    </header>
    
    <h1> Hi </hi>

    <script>
      require('renderer.js');
    </script>


  </body>
</html>
知道发生了什么吗?我非常确定
renderer.js
文件根本没有加载。

require('./renderer.js')
const { app, BrowserWindow } = require('electron');
const path = require('path');

if (require('electron-squirrel-startup')) {
  app.quit();
}

let win = null;

function boot(){
  win = new BrowserWindow({
    width: 600,
    height: 400,
    frame: false,
    webPreferences: {
      nodeIntegration: true
    }
  })
  win.loadFile(path.join(__dirname, 'index.html'));
}

app.on('ready', boot);

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});