Electron开发实战——本地epub阅读器(简介)

2020-09-18

基于electron的web项目-桌面级epub阅读器,代码已在gitHub开源。 代码仓库:Nread

技术栈

1.安装Electron-vue并初始化(electron版本号为8.4.1)

# 安装 vue-cli 和 脚手架样板代码(npm下载慢可以用cnpm)
npm install -g vue-cli
vue init simulatedgreg/electron-vue my-project
#引入ant-design
npm install ant-design-vue --save

安装之后可能会出现 ReferenceError: process is not defined 错误,需要修改.electron-vue/webpack.web.config.js 和.electron-vue/webpack.renderer.config.js中的 HtmlWebpackPlugin对象内容

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

注意: ant-design可能不会使用时可能不会生效,需要在webpack.renderer.config.js里面加入白名单,才能使用

let whiteListedModules = [
            'vue', 
            'axios',
            'vue-electron',
            'vue-router',
            'vuex',
            'vuex-electron',
            'element-ui',
            'ant-design-vue'
    ]

2.epubjs用来解析epub书籍的,epubjs使用时可能会报错,由于语法问题,需要修改导出的语法

(待续…..)