乡亲

我试图在Ionic 3测试应用程序中打开ePub文件,但未成功。

我通过npm安装了epubjs。 Package.json为:

{
  "name": "app_name",
  "author": "Author",
  "homepage": "http://example.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/animations": "4.1.3",
    "@angular/common": "4.1.3",
    "@angular/compiler": "4.1.3",
    "@angular/compiler-cli": "4.1.3",
    "@angular/core": "4.1.3",
    "@angular/forms": "4.1.3",
    "@angular/http": "4.1.3",
    "@angular/platform-browser": "4.1.3",
    "@angular/platform-browser-dynamic": "4.1.3",
    "@angular/platform-server": "4.1.3",
    "@ionic-native/core": "3.12.1",
    "@ionic-native/device": "^3.12.1",
    "@ionic-native/network": "^3.12.1",
    "@ionic-native/splash-screen": "3.12.1",
    "@ionic-native/status-bar": "3.12.1",
    "@ionic-native/transfer": "^3.12.1",
    "@ionic/storage": "2.0.1",
    "epubjs": "^0.2.20",
    "ionic-angular": "3.4.0",
    "ionicons": "3.0.0",
    "ng2-pdf-viewer": "^1.1.0",
    "rxjs": "5.4.0",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.12"
  },
  "devDependencies": {
    "@ionic/app-scripts": "1.3.7",
    "@ionic/cli-plugin-ionic-angular": "1.3.1",
    "typescript": "2.3.4"
  },
  "cordovaPlugins": [
    "cordova-plugin-whitelist",
    "cordova-plugin-console",
    "cordova-plugin-statusbar",
    "cordova-plugin-device",
    "cordova-plugin-splashscreen",
    "ionic-plugin-keyboard"
  ],
  "cordovaPlatforms": [],
  "description": "readerApp"
}


在阅读器页面(pages / reader / reader.ts)中导入epubjs(import {epubjs} from 'epubjs';)似乎可以。但是,当我尝试创建ePub图书(let book = epubjs.ePub(url))时,在应用运行时出现以下错误消息:

未捕获的错误:模块解析失败:/home//dev_mobile//node_modules/@ionic/app-scripts/dist/webpack/transpile-loader.js!/home//dev_mobile//node_modules/epubjs/server.js意外字符' #'(1:0)
您可能需要适当的加载程序来处理此文件类型。
| #!/ usr / bin / env节点
| var connect = require('connect'),
| colors = require('colors'),。 。 。

过去3天没有任何线索的Google搜索。有人也有吗?

我的猜测是epubjs集成还不太成熟,但是我对如何解决它知之甚少= |

最佳答案

您需要将epubjs文件夹复制到src / assets,然后参考必要
src / index.html中的文件

<script src="assets/epubjs/build/epub.min.js"></script>
<script src="assets/epubjs/build/libs/zip.min.js"></script>


然后在您的页面中:

declare var ePub: any;
let book = ePub("assets/books/moby-dick/");


https://github.com/janpio/ionic-epubjs

10-08 11:38