2016-09-21 11 views
0

我無法獲得cordova-promise-fs在我的科爾多瓦應用程序中工作。CordovaPromiseFS未定義

我有:index.html,其中包含由browserify創建的一個js文件。這個js文件包含cordovapromisefs.js,promiscuous.js和我自己的代碼的內容,那就是:

require('../node_modules/cordova-promise-fs/dist/CordovaPromiseFS.js'); 

var fs = CordovaPromiseFS({ 
      persistent: true, // or false 
      storageSize: 20 * 1024 * 1024, // storage size in bytes, default 20MB 
      concurrency: 3, // how many concurrent uploads/downloads? 
      Promise: require('../node_modules/promiscuous/promiscuous.js') // Your favorite Promise/A+ library! 
     }); 

(function() { 
    "use strict"; 


    document.addEventListener('deviceready', onDeviceReady.bind(this), false); 

    function onDeviceReady() { 
     console.log(fs); 
    }; 
})(); 

我想這應該把工作做好,但現在,我將「未捕獲的ReferenceError:CordovaPromiseFS沒有定義「

願意指出正確的方向。

回答

0

您使用Browserify建立你的包,所以不是要求已經捆綁cordova-promise-fs/dist/CordovaPromiseFS.js文件,要求模塊本身,就像這樣:

var CordovaPromiseFS = require('cordova-promise-fs'); 

,其中將包括cordova-promise-fs/index.js文件在您一束 - 與已經捆綁的文件不同 - 是一個輸出工廠功能的CommonJS模塊。

+0

就是這樣,謝謝!顯然,我並沒有完全瞭解到browserify已經在做什麼以及需要做什麼。 – Wheelie

0

嘗試和分配,從require返回值:

var CordovaPromiseFS = require('../node_modules/cordova-promise-fs/dist/CordovaPromiseFS.js'); 

,你也可以建立CordovaPromiseFS作爲瀏覽器庫自己,用的WebPack。 the repo's readme建議您克隆源和運行提供prepublish命令:

npm install webpack -g 
npm run-script prepublish 

這個命令基本上包CordovaPromiseFS的index.js文件和包裝DIST文件,並將其暴露給一個變量(see the source)。