I can't access variables after webpack compilation. I need it, because i'm using this variable to call function in onclick.
code is like
function DetailClass() {
this.add = function() {
console.log(1);
}
}
var Detail = new DetailClass();
Webpack including this code into eval()
And in HTML i call it like
<div onclick="Detail.add();">Add</div>
In your webpack configuration you have to specify output.library
and output.libraryTarget
.
Here's a guide: https://webpack.github.io/docs/configuration.html#output-library
For following configuration:
...
output:{
...
library: 'MyLib',
libraryTarget: 'var'
}
...
You will be able to use it like:
<div onclick="MyLib.Detail.add();">Add</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With