I'm using one js file bundled through webpack.
I'm in a little unusual situation right now.
I have to run js in Java, use GraalVm.
To explain it briefly, I have to call from Java through the function name of js.
Value test = context.getBindings("js").getMember("testFunction");
However, when bundling with a webpack, it is not called because this function is not global.
app.js
const {decodeAddress, encodeAddress} = require('@polkadot/keyring');
const {hexToU8a, isHex} = require('@polkadot/util');
function testFunction(address) { //I want this function.
try {
encodeAddress(
isHex(address) ? hexToU8a(address) : decodeAddress(address)
);
console.log("address : " + address);
return true;
} catch (error) {
console.log("wrong address :" + address +error);
return false;
}
}
webpack.config.js
const path = require("path");
module.exports = {
entry: path.resolve(__dirname, 'app.js'),
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
library: 'EntryPoint',
},
optimization: {
minimize:false
},
resolve: {
alias: {
'@polkadot/wasm-crypto-wasm/packageInfo': require.resolve('@polkadot/wasm-crypto-wasm/packageInfo'),
'@polkadot/wasm-crypto-wasm': require.resolve('@polkadot/wasm-crypto-wasm/empty'),
'@polkadot/wasm-crypto-asmjs/packageInfo': require.resolve('@polkadot/wasm-crypto-asmjs/packageInfo'),
'@polkadot/wasm-crypto-asmjs': require.resolve('@polkadot/wasm-crypto-asmjs/data')
}
}
}
last of bundle.js
(() => { //I think, I have to remove this arrow function. is it right?
const {decodeAddress, encodeAddress} = __webpack_require__(7491);
const {hexToU8a, isHex} = __webpack_require__(9215);
function testFunction(address) {
console.log(address);
try {
encodeAddress(
isHex(address)
? hexToU8a(address)
: decodeAddress(address)
);
console.log("address : " + address);
return true;
} catch (error) {
console.log("wrong address :" + address +error);
return false;
}
}
})();
please help me :)
I'm not use HTML. i want single bundle.js (accesible function!)