New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import PixiJS as ESM without bundlers #6734
Comments
Rollup, Webpack and Parcel all can provide builtin polyfills for Node’s url and path utils. I’m 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’d 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. |
That's the thing... I'd like to use no such tools. |
Just because it’s a web standard doesn’t mean Pixi supports it. There are lots of modern browser features that we don’t 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’s 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 here are the official builds from the dev branch. We don't yet have a release, but these will be in v5.4.0.
Examplehttps://github.com/bigtimebuddy/pixi.js-browser-module-example |
Any idea where how to import types for ES6 imports with types? |
tell me your set up. I thought types are working in all configs |
Thanks you your prompt response! I'm using TypeScript using ESM imports. I'm not using a bundler - simple converting all the .ts files to .js for now. I'm using gulp to do this. I have a TypeScript file where I'm trying to access pixi.js, copied out of I then copied the
The source on the page I'm using looks like this: import * as PIXI from "../../pixi/pixi.js";
export class _DropJoystick {
private readonly canvas:HTMLCanvasElement;
private readonly pixiApp:PIXI.Application;
private readonly window:Window;
constructor(_window:Window, canvas:HTMLCanvasElement) {
this.canvas = canvas;
this.window = _window;
this.pixiApp = new PIXI.Application({width: this.window.innerWidth, height: this.window.innerHeight, view: canvas, transparent:true, resizeTo:this.window, antialias:true});
}
test() {
let g = new PIXI.Graphics();
g.beginFill(0xFF0000)
g.drawCircle(50,50, 100);
this.pixiApp.stage.addChild(g);
}
} Perhaps my whole approach is wrong, but I'd really like to use simple ES6 imports, just writing in typescript and converting each file to JavaScript. Happy to be pointed in a different direction. I see there is mention of a |
Can this help you? https://github.com/pixijs/pixijs/wiki/v6-Migration-Guide#typings |
No idea why that worked, but it did. Thank you!!! |
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?
The text was updated successfully, but these errors were encountered: