2

Easy question. In my .js code, inside a module, I had something like:

var MyVar = MyVar || 'anyOtherValue'

When Webpack creates the 'Build" it covnerts it to:

var a = a || 'anyOtherValue' 

THE PROBLEM with that is that my HTML is converted by another team into .jsp for a MPA. In each page the backend team injects a Global variable (MyVar) which will be used by the javascript if present:

page1.jsp

<script>
   var myVar="New Value";
</script>

Question is: ¿How can I tell Webpack to 'leave' myVar variable with its current name instead of transforming it?

I did following workaround which seems awful to the eyes, though it works:

window.myVar = window.myVar || 'someValue';

Thanks in advance

Barleby
  • 618
  • 2
  • 9
  • 20
  • Your solution is actually a proper one. As webpack is working with modules, it has no idea that this specific variable should be accessed / taken from outside. You can read more about this here: https://stackoverflow.com/questions/37656592/define-global-variable-with-webpack – Alex Brohshtut Mar 20 '20 at 09:04

0 Answers0