I am trying to bundle the Javascript library cookpete/poker-odds so I can use it in Swift JavascriptCore. When I bundle the code with webpack, and then run const bundle = require("./bundle.js") in Node REPL, bundle is an empty object. I expect this object to export the functions marked with export in the source code. I tried modifying the code (added module.exports = {...}) before bundling to ensure my desired function is exported, but there was still nothing exported.
My process:
git clone https://github.com/cookpete/poker-odds.git && cd poker-odds
npm run build // generate the /lib directory
add webpack.config.js // see below
npx webpack // generate bundle.js in dist directory
cd dist // move to dist directory
node // launch node REPL
const bundle = require("./bundle.js")
console.log("bundle:", bundle) // prints bundle: {}; I want this object to contain calculateEquity()
webpack.config.js:
module.exports = {
mode: 'development',
entry: './lib/calculate.js', // Is this correct?
output: {
filename: 'bundle.js',
},
};
Questions:
- What is the correct
entryproperty forwebpack.config.js? I'm unclear on what I need to export thecalculateEquity()function. - The library uses
babel. Is this causing a problem? - The library appears to generate a
.jsonfile during building. Is this a problem?
Thanks.