当 textisolation 为真时如何使用 node_modules?

问题描述 投票:0回答:0

我目前正在使用 Electron 制作应用程序,但是当我打包我的应用程序时,当我设置参数时出现白屏

textisolation: true
.

但是当我将它设置为

false
时,我的模块如
jquery
sqlite3
没有定义。

这里是三段代码:

main.js

const path = require('path');
const { app, BrowserWindow, screen } = require('electron')
const EventEmitter = require('events')
app.commandLine.appendSwitch("ignore-certificate-errors");
const loadingEvents = new EventEmitter()
let win
app.on('ready', () => {  
  const { width, height } = screen.getPrimaryDisplay().workAreaSize
  window = new BrowserWindow({
    width,
    height,
    minWidth:970,
    minHeight:390,
    icon: 'icon.png',
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
      contextIsolation: true,
      webSecurity: false,
    }
  })
  
  window.loadFile((path.join(__dirname, '/html/loading.html')))

  // Our loadingEvents object listens for 'finished'
  loadingEvents.on('finished', () => {
    window.loadFile((path.join(__dirname, '/html/index.html')))
    window.webContents.openDevTools()
  })

  setTimeout(() => loadingEvents.emit('finished'), 5000)
})

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
    <link rel="stylesheet" href="../css/index.css" type="text/css">
    <title>MyApp</title>
  </head>
  <body class="container">
    <div class="topnav" id="myTopnav">
      <a id="name">MyApp</a>
      <a href='index.html'>Home</a>
      <a href='get.html'>Live TV</a>
      <a href='post.html'>Movies</a>
      <a href='inline.html'>Series</a>
      </a>
    </div>
  </body>
  <script src="../js/index.js"></script>
</html>

index.js

const { get } = require('jquery');
var $ = jQuery = require("jquery")
var mysql = require('mysql');
var sq = require('sqlite3');
require('dotenv').config()

我尝试了几种解决方案,但不幸的是没有成功。

你知道解决这个问题的方法吗?

非常感谢您的帮助。

javascript node.js electron requirejs electron-builder
© www.soinside.com 2019 - 2024. All rights reserved.