如何在电子应用程序中正确包含 twitter bootstrap?

How to properly include twitter bootstrap in electron app?

这是我的第一个electron app,它是基于快速启动的app。我想添加 twitter bootstrap 的 css。所以我是这样安装的:

npm install bootstrap

并像这样包含在 index.html 中:

<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">

当我从终端 运行: npm start 时它工作正常。但是,当我尝试使用这样的电子包装器构建它时:

npm run build

我有一个本机 mac 应用程序 "myApp.app",但是当我打开它时,我看不到样式。

应用程序中除了 node_modulespackage.json 之外的唯一文件是:main.jsindex.html,它们都在根目录中。

这里有我遗漏的步骤吗?

编辑

我发现应用程序正在 Resouces/app 目录中查找 css 文件。包含 css 文件是构建工具的责任,还是我应该手动包含它?如果我必须处理这个问题,我什至需要从 npm 安装 bootstrap 吗?

检查您的 package.json 文件:bootstrap 是否被列为依赖项?可能不是,因为它看起来不像你在使用 --save 参数:

npm install bootstrap --save

我不是 Electron 英雄:我目前正在使用 fs-jetpack 进行一个项目。我从 project.json 中删除了 fs-jetpack 条目,并使用 electron-packager 进行了 OSX 构建。在启动时,我收到一个脚本错误,关于缺少 "fs-jetpack'. From that I conclude that the packager uses the 'package.json` to know what to include. Maybe I'm wrong? I have "--prune=true" 作为打包程序参数之一。也许没有它包含一切?

此外,我很惊讶这条线对你有用:

<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">

但也许您使用的是不同的文件夹结构,其中 index.html 文件不在应用程序目录中?