第十一章:Electron-Vue创建项目

修改前:

在这里插入图片描述

修改后:

在这里插入图片描述

plugins: [

new VueLoaderPlugin(),

new MiniCssExtractPlugin({filename: ‘styles.css’}),

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: false

}),

new webpack.DefinePlugin({

‘process.env.IS_WEB’: ‘true’

}),

new webpack.HotModuleReplacementPlugin(),

new webpack.NoEmitOnErrorsPlugin()

],

2、webpack.renderer.config.js

修改前:

在这里插入图片描述

修改后:

在这里插入图片描述

plugins: [

new VueLoaderPlugin(),

new MiniCssExtractPlugin({filename: ‘styles.css’}),

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

}),

new webpack.HotModuleReplacementPlugin(),

new webpack.NoEmitOnErrorsPlugin()

],

  • 运行结果(npm run dev)

在这里插入图片描述


让vscode代码提示

当前项目下

cnpm install electron --save

使用 js-cookie

cnpm i js-cookie


打包

npm run build

  • 问题一:Error: Unresolved node modules: vue, highcharts,***

解决方案

删除node_modules

使用 npm install (不是使用cnpm会出问题)

  • 问题二:electron 打包一直downloading

在 文件夹跟目录下新建文件 .npmrc,内容如下:

electron_mirror=http://npm.taobao.org/mirrors/electron/

registry=https://registry.npm.taobao.org

在这里插入图片描述

再次进行num run build 速度就会快起来

  • 项目的图片资源报错

图片资源不要放在assets中,放在static目录下

在这里插入图片描述

path.join(__static, ‘yuma.png’)

  • 左上角的图标不显示

这是build/icons/icon.ico制作的问题,可以选择IconWorkshop软件来制作

  • 左上角默认系统名称

在主进程中设置

//设置系统名称(也是初始化左上角名称——项目名称在index.ejs中修改)

app.setName(“舆情监控系统”)

在这里插入图片描述

  • 启动时白屏

在主进程中

mainWindow = new BrowserWindow({

height: 800,

useContentSize: true,

width: 1200,

show: false //先隐藏

})

mainWindow.loadURL(winURL)

mainWindow.on(‘ready-to-show’, () => {

mainWindow.show() //初始化后再显示

//右键菜单

require(‘./model/menu’)

//系统托盘

require(‘./model/tray’)

})

在这里插入图片描述

注意require引入时要放在mainWindow.show()之后,否则报错

  • 点击桌面图标只开启一个应用

在主进程中底部直接添加

const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {

// Someone tried to run a second instance, we should focus our window.

if (mainWindow) {

if (mainWindow.isMinimized()) mainWindow.restore()

mainWindow.focus()

mainWindow.show()

}

})

最后

文章到这里就结束了,如果觉得对你有帮助可以点个赞哦

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

eSingleInstance((commandLine, workingDirectory) => {

// Someone tried to run a second instance, we should focus our window.

if (mainWindow) {

if (mainWindow.isMinimized()) mainWindow.restore()

mainWindow.focus()

mainWindow.show()

}

})

最后

文章到这里就结束了,如果觉得对你有帮助可以点个赞哦

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

[外链图片转存中…(img-hlEdgwfB-1714199063501)]

  • 9
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值