我已经在SO和Google上搜索了很长时间,但是找不到任何好的答案。我们正在运行webpack v4,我想包含Epsons术语打印机js库(epos-2.9.0),可以下载here。
代码看起来像这样:
(function(window,undefined){function callbackInfo(){this.callbackInfoList=new Object()}callbackInfo.prototype={addCallback:function(callback,sq){this.callbackInfoList[sq]=callback},removeCallback:function(sq){for(var i in this.callbackInfoList){if(i==sq){delete this.callbackInfoList[i];return}}},getCallback:function(sq){if(this.callb....
根据他们的文档,我需要以下代码来打印某些内容:
var canvas = document.getElementById('canvas');
var printer = null;
var ePosDev = new epson.ePOSDevice();
ePosDev.connect('192.168.1.82', 8008, cbConnect);
function cbConnect(data) {
if(data == 'OK' || data == 'SSL_CONNECT_OK') {
ePosDev.createDevice('local_printer', ePosDev.DEVICE_TYPE_PRINTER,
{'crypto':false, 'buffer':false}, cbCreateDevice_printer);
} else {
alert(data);
}
}
function cbCreateDevice_printer(devobj, retcode) {
if( retcode == 'OK' ) {
printer = devobj;
printer.timeout = 60000;
printer.onreceive = function (res) { alert(res.success); };
printer.oncoveropen = function () { alert('coveropen'); };
print();
} else {
alert(retcode);
}
}
function print() {
printer.addText('Hello\n');
printer.send();
}
我尝试使用webpackexports-loader将其全局导出:
{
test: require.resolve('./src/epos-2.9.0.js'),
use: 'exports-loader?epson'
}
但是没有用,尝试将它包含在index.html中(全局),但是随后找不到它(我想我需要告诉webpack导出.js)。
在我的代码中获得epson功能的最佳方法是什么?