Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
How to export function to global when bundling from webpack

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!)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!