layers icon indicating copy to clipboard operation
layers copied to clipboard

Import in Angular 9

Open CardzMania opened this issue 4 years ago • 10 comments

import * as PIXI from 'pixi.js'; import 'pixi-layers';

doesn't work, tried a lot of other variations also but to no avail.

Please advise how we can import it with Angular 9, thanks!

CardzMania avatar Jun 14 '20 15:06 CardzMania

as said in README,

import * as PIXI from "pixi.js";
window.PIXI = PIXI;
require("pixi-layers")

if it doesnt work for you - im sorry, i cant support angular 9 because i am not writing on angular 9 stuff. There were manuy issues with that in pixi plugins, we are working on new super-system for all plugins that will solve it.

ivanpopelyshev avatar Jun 14 '20 19:06 ivanpopelyshev

Thanks for the quick response, I tried that as well, doesn't work. Any ETA for the new "super-system"?

Any recommendation how I could merge the two js myself to use as one combined js?

CardzMania avatar Jun 14 '20 19:06 CardzMania

ETA - Previous year :) Recomendation - there were a few issues with angular in main pixi repo, look in closed issues.

ivanpopelyshev avatar Jun 14 '20 21:06 ivanpopelyshev

Thanks, I know that feeling, we wanted to launch with pixi magic two years ago! :)

But seriously, any realistic chance of having this new framework available soon? Just trying to get an idea so we can plan things accordingly. Thanks a ton!

CardzMania avatar Jun 14 '20 22:06 CardzMania

add PIXI into script to load directly in angular.json, in build options:

"scripts": [ "node_modules/pixi.js/dist/pixi.min.js" ]

Then no need to import * as PIXI from 'pixi.js' in the project after that, just import your plugins as needed! Hope it helps!

lycwed avatar Jul 13 '20 08:07 lycwed

The only way we were able to run pixi, pixi-layers and Angular was by using a custom webpack configuration to provide PIXI globally. This way webpack can also bundle up all dependencies, which would not be possible when importing the minifed script directly as stated by @lycwed.

// custom-webpack-config.js
const webpack = require("webpack");
module.exports = {
  plugins: [
    new webpack.ProvidePlugin({
      PIXI: "pixi.js",
    }),
  ],
};

Adapt your angular.json accordingly:

"architect": {
  "build": {
    "builder": "@angular-builders/custom-webpack:browser",
    "options": {
      "customWebpackConfig": {
        "path": "./custom-webpack.config.js"
      },
      ...
    },
  },
  "serve": {
    "builder": "@angular-builders/custom-webpack:dev-server",
    ...
  }
}

This requires two new dependencies: @angular-builders/custom-webpack and @angular-builders/dev-server.

You can read more about custom webpack configurations in Angular here: https://www.digitalocean.com/community/tutorials/angular-custom-webpack-config

ChristophWalter avatar Oct 23 '20 10:10 ChristophWalter

Trying to get pixi-layers plugin to work with angular & webpack, but no success for now.

@ChristophWalter also tried the approach with custom webpack config, but got following error TypeError: pixi_layers__WEBPACK_IMPORTED_MODULE_1__.Layer is not a constructor

Code:

import * as PIXI from 'pixi.js';
import * as PIXILayer from 'pixi-layers';
public pixiContainer: PIXILayer.Layer = new PIXILayer.Layer();

Maybe something wrong with the imports?

Flippsor avatar Jan 14 '21 20:01 Flippsor

I don't use this package anymore, but here's how I did it :

import * as PIXI from 'pixi.js';
import 'pixi-layers';

public pixiContainer: PIXI.display.Layer = new PIXI.display.Layer();

If you use PIXI layer to use zOrder, you better use pixijs v5 and zIndex, it's what I use now ;)

lycwed avatar Jan 15 '21 12:01 lycwed

Going to try it out. The problem with PIXI zIndex is that the index only sorts all childs within a parent.

In my application i need to sort through several parents. As far as i know this is not possible with PIXI zIndex.

Flippsor avatar Jan 15 '21 13:01 Flippsor

PIXI has to be somewhere in globals, in window, before pixi-layers is imported. Provided maybe, that's why i usually use require('pixi-layers');. We are fixing all that in upcoming pixi v6 very soon.

ivanpopelyshev avatar Jan 15 '21 14:01 ivanpopelyshev