我正在尝试使用webpack来转换(并捆绑)我为电子主(不是渲染器)编写的ES6代码。当我运行并运行时,应用程序运行正常。但是在捆绑electron-packager
图标图像(我用于托盘)之后无法加载。
以下是我尝试运行由electron-packager
构建的exe(我在Windows 10上)时遇到的错误:
以下是电子主要过程的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;