Parcel: What is the equivalent of webpack's "libraryTarget: 'window'"?

Created on 26 Nov 2019  路  1Comment  路  Source: parcel-bundler/parcel

馃敠 Context

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.

馃捇 Code Sample

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...

Question

Most helpful comment

There is https://parceljs.org/cli.html#expose-modules-as-umd:

parcel serve entry.js --global myvariable

-> globalvariable.main()

>All comments

There is https://parceljs.org/cli.html#expose-modules-as-umd:

parcel serve entry.js --global myvariable

-> globalvariable.main()

Was this page helpful?
0 / 5 - 0 ratings