使用模板搭建electron_edgeJS_vue_typescript

前言

使用模板搭建 electron与edgeJS与vue与typescript

使用模板搭建electron_edgeJS_vue_typescript

1. 安装@vue/cli与@vue/cli-init

npm install -g @vue/cli;
npm install -g @vue/cli-init

2. 创建项目

vue init simulatedgreg/electron-vue my-project
根据需要选择
运行效果:
效果图

出现错误:
错误图

解决方法:
在webpack.renderer.config.js添加

      templateParameters(compilation, assets, options) {
        return {
          compilation: compilation,
          webpack: compilation.getStats().toJson(),
          webpackConfig: compilation.options,
          htmlWebpackPlugin: {
            files: assets,
            options: options
          },
          process,
        };
      }

位置

重新执行命令
运行效果:
运行图

3. 安装electron-edge-js

npm install electron-edge-js

4. 安装typescript

npm install typescript
npm install ts-loader

5. 配置typescript与vue

①src目录下创建vue.sfc.d.ts全局声明文件:

// 配置ts读取.vue文件
declare module "*.vue"{
  import Vue from 'vue'
  export default Vue
}

②更新webpack,用于解析ts-loader

webpack.web.config.js与webpack.renderer.config.js
在rules添加下面所示

      {
        test: /\.ts$/,
        use: {
          loader: "ts-loader",
          options: {
            appendTsSuffixTo: [/\.vue$/],
          }
        }
      }

extensions 添加’.ts’,如下所示

extensions: ['.js', '.ts','.vue', '.json', '.css', '.node', '.ts']

webpack.main.config.js

      {
        test: /\.ts$/,
        loader: 'ts-loader',
        exclude: /node_modules/,
        options: {
          transpileOnly: true,
        }
      }

③把src下面的js文件改成ts
别忘了把webpack里匹配的路径改为ts,如:

原来:path.join(__dirname, '../src/main/index.js')
改后:path.join(__dirname, '../src/main/index.ts')

dev-runner.js里的这个不要改

  var args = [
    '--inspect=5858',
    path.join(__dirname, '../dist/electron/main.js')
  ]

改后会发现几处错误:
在renderer/main.ts

import App from './App'
Vue.http = Vue.prototype.$http = axios

需改为:

import App from './App.vue'
Vue['http'] = Vue.prototype.$http = axios

在main.index.ts
加上

declare namespace global {
  let __static: string
}

6. 运行

运行图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值