npm install --global yarn
npm install -g node-gyp
npm install --global --production windows-build-tools
// 创建项目
vue init simulatedgreg/electron-vue my-project
// 安装依赖(有条件可通过科学上网进行安装,否则有些地方会卡住)
cd my-project
yarn // 或者 npm install
yarn run dev // 或者 npm run dev
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
nodeModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, '../node_modules')
: false
}),
点此处下载devTools.zip并解压放在项目根目录中 提取码: aa84
// Install `vue-devtools`
require('electron').app.on('ready', () => {
// 注释掉的这部分是 Electron-Vue 中预装devtool的代码,没有用
// let installExtension = require('electron-devtools-installer')
// installExtension.default(installExtension.VUEJS_DEVTOOLS)
// .then(() => {})
// .catch(err => {
// console.log('Unable to install `vue-devtools`: \n', err)
// })
// 新增的:安装vue-devtools
BrowserWindow.addDevToolsExtension(path.resolve(__dirname, '../../devTools/vue-devtools'));
});
nsis-resource-3.3.0.zip 提取码:7hb7
nsis-3.0.3.2 提取码:b444
winCodeSign-2.4.0 提取码:3ee9
electron-v2.0.18-win32-x64.zip 提取码:nrq3
chromedriver-v1.8.0-win32-x64.zip 提取码:gi8d
解压nsis-resource-3.3.0.zip,nsis-3.0.3.2,winCodeSign-2.4.0
// NB: Don't open dev tools with this, it is causing the error
require('electron-debug')();
// Open dev tools initially when in development mode
if (process.env.NODE_ENV === "development") {
mainWindow.webContents.on("did-frame-finish-load", () => {
mainWindow.webContents.once("devtools-opened", () => {
mainWindow.focus();
});
mainWindow.webContents.openDevTools();
});
}
mainWindow = new BrowserWindow({
height: 563,
useContentSize: true,
width: 1000,
autoHideMenuBar: true,
})
mainWindow.setMenu(null)
mainWindow.loadURL(winURL)