Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

223
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda