Skip to content
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 in Angular 9 #57

Open
CardzMania opened this issue Jun 14, 2020 · 10 comments
Open

Import in Angular 9 #57

CardzMania opened this issue Jun 14, 2020 · 10 comments

Comments

@CardzMania
Copy link

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!

@ivanpopelyshev
Copy link
Collaborator

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.

@CardzMania
Copy link
Author

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?

@ivanpopelyshev
Copy link
Collaborator

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

@CardzMania
Copy link
Author

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!

@lycwed
Copy link

lycwed commented Jul 13, 2020

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!

@ChristophWalter
Copy link

ChristophWalter commented Oct 23, 2020

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

@Flippsor
Copy link

Flippsor commented Jan 14, 2021

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?

@lycwed
Copy link

lycwed commented Jan 15, 2021

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 ;)

@Flippsor
Copy link

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.

@ivanpopelyshev
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants