parallel-js/parallel.js

include in script form?

havok2063 opened this issue · 4 comments

I would like to use this library to parallelize front-end loading using map. The main page indicates I can include this code as a script using <script src="parallel.js"></script>, instead of installing with npm. However, this fails because the file is still a source file rather than compiled, and I get errors like require is not defined. I have a project that mostly uses javascript as scripts rather than backend compiled sources where I can import and require modules. Is there a compiled version somewhere that I can just drop into my project? Or does anyone know how to get this working?

this is a quite common issue when use a npm package inside of browser.

You might want to try a cdn like skypack to load it directly:

import parallel from 'https://cdn.skypack.dev/paralleljs';

Is this something I need to build and compile myself in a new js file? Or can I include this directly in the browser? I tried

<script type='module'>
import parallel from 'https://cdn.skypack.dev/paralleljs';
</script>

but I also got an error about the os package

Uncaught Error: [Package Error] "os" does not exist. (Imported by "paralleljs").
    <anonymous> https://cdn.skypack.dev/error/node:os?from=paralleljs:14

I also tried bundling a new js file using rollup with the import line included, and doing export { parallel } just to check that I had access to the code in the browser but it didn't work.

I found a version of it here that seems to work, https://unpkg.com/paralleljs@1.0.1/lib/parallel.js with <script src='https://unpkg.com/paralleljs@1.0.1/lib/parallel.js'></script>