O
O
olifem2019-02-27 15:05:40
JavaScript
olifem, 2019-02-27 15:05:40

How to initialize js class in index.html with a separate file?

I'm using webpack to build scripts into one file.
When initializing a class from mainBoundle.js to index.html , the compiler reports that it doesn't see it. If you copy the class to index.html - everything works.
How to initialize js class in index.html with a separate file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Bogdanov, 2019-02-27
@olifem

As far as I know in index.html you can only access variables available in the global scope. If you need to access a class from mainBoundle.js write it to window. Something like this:

class SomeClass {
  // ...
}
window.__SomeClass = SomeClass;

And in index.html call
new window.__SomeClass()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question