Electron + vue 新建项目

最近想学一下桌面端的开发,所以选择使用 electron + vue 框架
话不多说直接上代码

1 安装node环境

这个我就不多说了

3 创建electron vue 项目

//0.如果没有安装vue-cli 请全局安装vue cli
//npm install @vue/cli -g
//1.安装使用vue-cli 脚手架模板 simulatedgreg/electron-vue
vue init simulatedgreg/electron-vue  你的项目名
//2.下载依赖
npm install
//3.重新下载electron依赖,不重新下载可能会报错
npm i electron -D
//4.运行
npm run dev

如果报错: process is not defined

下面内容转自:知乎:electron-vue ReferenceError process is not defined
1、找到根目录下的.electron-vue目录

2、找到该目录下的webpack.renderer.config.js文件,找到这段代码:

new HtmlWebpackPlugin({
  // ...
})

3、用下面的代码将这段代码替换:

new HtmlWebpackPlugin({
      filename: 'index.html',
      template: path.resolve(__dirname, '../src/index.ejs'),
      minify: {
        collapseWhitespace: true,
        removeAttributeQuotes: true,
        removeComments: true
      },
      templateParameters(compilation, assets, options) {
        return {
          compilation: compilation,
          webpack: compilation.getStats().toJson(),
          webpackConfig: compilation.options,
          htmlWebpackPlugin: {
            files: assets,
            options: options
          },
          process,
        };
      },
      nodeModules: process.env.NODE_ENV !== 'production'
        ? path.resolve(__dirname, '../node_modules')
        : false
 }),

4、再找到该目录下的webpack.web.config.js文件,找到这段代码:

new HtmlWebpackPlugin({
  // ...
})

5、用下面的代码将这段代码替换:

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
}),

6、最后重新编译就解决了(注意两个文件替换的内容是不一样的)

启动

npm run dev
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值