Is it possible, with a JavaScript based npm OpenFL project, to make use of other npm JavaScript libs?
For the purpose of example, I’ve been trying to integrate ws (npmNode.js WebSocket library) to make use of its WebSocketServer (my related post).
I’m able to bring in the ws library through npm install ws
, updated wepack.common.js
to include a reference to it and imported it in app.js
.
However, it’s failing to compile because webpack encounters an “unexpected token”:
[339] ./node_modules/ws/lib/websocket-server.js 202 bytes {0} [built] [failed] [1 error]
+ 337 hidden modules
ERROR in ./node_modules/ws/lib/websocket-server.js
Module parse failed: Unexpected token (55:6)
You may need an appropriate loader to handle this file type.
| path: null,
| port: null,
| ...options
| };
|
@ ./src/app.ts 15:25-59
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/app.ts
The token it’s referring to there, is this piece of JavaScript code:
...options
This appears quite a lot in the ws library and to be honest, I’m not sure what to make of it. I’m not familiar with this specific ...options
syntax.
This is a more complete snippet of that portion of the ws websocket-server.js code:
constructor(options, callback) {
super();
options = {
maxPayload: 100 * 1024 * 1024,
perMessageDeflate: false,
handleProtocols: null,
clientTracking: true,
verifyClient: null,
noServer: false,
backlog: null, // use default (511 as implemented in net.js)
server: null,
host: null,
path: null,
port: null,
...options
};
I’ve tried building the project as ES5, ES6 and now TypeScript, with the same results.
I’d appreciate any pointers, thank you.