E
E
etmoandy2018-08-15 10:14:33
JavaScript
etmoandy, 2018-08-15 10:14:33

How to get a variable from a script compiled by Babel?

module.js

const Module = (() => {
  class Module {
    static init() {
      alert('it works!')
    }
  }
  return Module
})()

export default Module

app.js
import Module from './module'

export { Module }

index.html
<script src="app.js"></script>
<script>
  Module.init();
</script>

As a result, it does not find the Module variable. I use Laravel Mix (and he in turn is Babel). How can I access the Module from the script tag without any type="module"?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rednakse, 2018-08-15
@etmoandy

window.Module = Module
?

P
profesor08, 2018-08-15
@profesor08

Line Module.init (); should be in the app.js file. It's all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question