Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

224
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda