My project is using another js library and needs to define a main() function (to be called by the other library). But when I run parcel src/index.js, I get the error main() is not defined.
src/index.js
export function main() {
List.addTitle('Hello World');
List.show();
}
dist/index.html
<html>
<head>
<script type="text/javascript" src="https://someOtherLibrary.js"></script>
<script type="text/javascript">
window.onload = function () {
window.eval("index.js");
main(); <!-- main is not defined -->
};
</script>
</head>
</html>
In webpack I had the same issue and the solution was to add libraryTarget: 'window' to the output config but I haven't been able to find such an option in parcel...
There is https://parceljs.org/cli.html#expose-modules-as-umd:
parcel serve entry.js --global myvariable
-> globalvariable.main()
Most helpful comment
There is https://parceljs.org/cli.html#expose-modules-as-umd:
->
globalvariable.main()