Pixi.js: Import PixiJS as ESM without bundlers

Created on 1 Jul 2020  路  10Comments  路  Source: pixijs/pixi.js

I'm trying to import Pixi in a Snowpack application, but, although the Pixi package on NPM contains a esm file (/lib/pixi.es.js), it can't be loaded directly in browser, as it uses node's native libs (e.g.: url).

Is it possible to import PixiJS as an ES Module, without the use of Rollup, Webpack or any other bundler?

馃檹 Feature Request

Most helpful comment

Okay, I hear you all. We will work on a browser-based ESM bundle.

All 10 comments

Rollup, Webpack and Parcel all can provide builtin polyfills for Node鈥檚 url and path utils. I鈥檓 not familiar with Snowpack, but could you overrides these? There are also public packages (e.g., url) by the same name you could may install alongside?

The other option is to remove any node-like dependencies from the project. I鈥檇 first try to find a Snowpack workaround for this problem before we do that. Also, those other bundles mentioned above are all unofficially supported by pixi. A Snowpack-based boilerplate project would be helpful to test this and work out the best way to support this tool too.

to support this tool too

That's the thing... I'd like to use no such tools.
Snowpack doesn't transform your code in anyway (it can, but that isn't the point). The idea is to use open web standards only.

Just because it鈥檚 a web standard doesn鈥檛 mean Pixi supports it. There are lots of modern browser features that we don鈥檛 support yet because adoption is low or we are still trying to run in a broad array of browsers. This is the first request for running ES modules directly. It鈥檚 not a bad idea but not a huge priority at the moment.

The ES build was added to support tree shaking with bundling not to run in the browser using module importing.

If someone wants to take on this task, we would consider a PR.

Quite a bummer you guys don't have an es module version.

This would be something great to have

Okay, I hear you all. We will work on a browser-based ESM bundle.

For the time being I created this. The problem I had was that transpiling the libraries in dev mode made it too slow. Hence the solution.

@SagnikPradhan 404 broken link 馃

@DrSensor Sorry, here is the new link. Ended up turning the simple script into a package.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

neciszhang picture neciszhang  路  3Comments

Makio64 picture Makio64  路  3Comments

sntiagomoreno picture sntiagomoreno  路  3Comments

lunabunn picture lunabunn  路  3Comments

lucap86 picture lucap86  路  3Comments