pixi-shim

pixijs shim for backend use of pixijs

Usage no npm install needed!

<script type="module">
  import pixiShim from 'https://cdn.skypack.dev/pixi-shim';
</script>

README

PIXI-SHIM

PIXI.js Back-End "shim". For mocking Canvas in Node.js with ❤️

https://badge.fury.io/js/pixi-shim https://snyk.io/test/github/Prozi/pixi-shim https://circleci.com/gh/Prozi/pixi-shim

Purpouse

  1. Designed for node - it makes you run universal javascript code that is designed with pixi.js on node.js environment

  2. It is very lazy - meaning it won't load anything twice and won't attempt to load it if it's not required

  3. It wont even load itself twice - while including multiple instances of pixi.js can cause Cannot redefine property isJson Error

Lazy loading

with lazy polyfill of

  • DOM
  • Window
  • Canvas
  • PIXI
  • other polyfills (requestAnimationFrame, etc.)

Usage

require("pixi-shim");

or if your game/app is feature-heavy and it still doesn't work, you might need to add pixi.js-legacy too

require("pixi-shim");
require("pixi.js-legacy");

Installation

$ yarn add pixi-shim

Example use (in node js env):

file1.js

const PIXI = require("pixi-shim");

file2.js

const PIXI = require("pixi-shim");

server.js

require("./file1");
require("./file2");

// No runtime conflicts, all dependencies have been included once

Canvas.toDataURL()

a bit hackish but works, see:

Tests

Total test suites: 2
Passed test suites: 2
Done in 4.35s.
ites: 0

Total tests: 10
Passed tests: 10
Failed tests: 0

Test Suite - /home/pietal/projects/pixi-shim/index.spec.js
passed - GIVEN pixi-shim THEN requiring it doesnt throw error
passed - GIVEN pixi-shim THEN new PIXI.Application doesnt throw error
passed - GIVEN pixi-shim THEN new PIXI.Sprite from base64 image does *not* work
passed - GIVEN pixi-shim THEN toDataURL does *not* yet work
passed - GIVEN pixi-shim THEN normal PIXI gameLoop works

Test Suite - /home/pietal/projects/pixi-shim/pixi.spec.js
passed - GIVEN pixi-shim/pixi THEN requiring it doesnt throw error
passed - GIVEN pixi-shim/pixi THEN new PIXI.Application doesnt throw error
passed - GIVEN pixi-shim/pixi THEN new PIXI.Sprite from base64 image *should* work
passed - GIVEN pixi-shim/pixi THEN toDataURL *should* work with pixi.js
passed - GIVEN pixi-shim/pixi THEN normal PIXI gameLoop works

https://app.circleci.com/pipelines/github/Prozi/pixi-shim

License

MIT (c) 2020-2022 Jacek Pietal