0

I'm using rollup and babel to transpile ES6 code. Now i need this Recaptcha Callback function to be triggered when the Captcha has been checked.

Problem is that tree shaking or another mechanism filters this function out during transpilation process.

How can i keep recaptchaCallback() in the final script to be triggered from outside?

import UIkit from 'uikit';

...

function recaptchaCallback() {
    document.getElementsByClassName('g-recaptcha')[0].style.border = 'none';
};

...
Mike
  • 5,416
  • 4
  • 40
  • 73
  • 1
    `window.recaptchaCallback` ? – lry Mar 26 '20 at 10:10
  • 1
    How is Recaptcha accessing the callback? You have it as a module-scoped function, so if it isn't actively accessed by code in the module, it is unreachable and rightly deleted. If it's meant to be global, as @ruoyanli mentioned, you need to assign it to a global. – loganfsmyth Mar 26 '20 at 14:04

1 Answers1

0

use sideEffects

A "side effect" is defined as code that performs a special behavior when imported, other than exposing one or more exports. An example of this are polyfills, which affect the global scope and usually do not provide an export.

{
  "name": "your-project",
  "sideEffects": [
    "./src/some-side-effectful-file.js"
  ]
}
SIMDD
  • 615
  • 5
  • 15