我正在尝试使用 webpack 转换(和捆绑)我为电子的主要(而不是渲染器)编写的 ES6 代码。当我编译并运行时,应用程序工作正常。但是在与图标图像(我用于托盘)捆绑后electron-packager
无法加载。
这是我尝试运行由以下内容构建的 exe(我在 Windows 10 上)时遇到的错误electron-packager
:
下面是电子主进程的 ES6 代码:
import electron, { app, BrowserWindow, Tray} from 'electron';
let appIcon = null;
let appIconPath = null;
if (process.platform === 'darwin') {
appIconPath = require('./resources/images/icon-black-16.png');
} else {
appIconPath = require('./resources/images/icon-16.png');
}
app.on('ready', () => {
// hide dock icon if possible
if (app.hasOwnProperty('dock')) {
app.dock.hide();
}
// tray icon
appIcon = new Tray(appIconPath);
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
});
这是我的 webpack 配置:
const path = require('path');
const SRC_DIR = path.resolve(__dirname, 'src/');
const DIST_DIR = path.resolve(__dirname, 'dist/');
var config = {
target: "electron",
entry: SRC_DIR + '/main.js',
output: {
path: DIST_DIR,
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.jsx?/,
include: SRC_DIR,
loader: 'babel-loader',
query: {
"presets": ["es2015", "react"]
}
},
{
test: /\.(png|ico)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader?name=files/[name].[ext]'
}
]
}
};
module.exports = config;