Angular 14 + PixiJS 的設定

 理由:

想說試著把PixiJS整到Angular 裡面,可能以後會用到PixiJS來做一些動畫相關的UI但是沒想到光是裝起來要能順順跑就遇到一堆問題。

Flow :

首先先用Angular CLI 建立專案然後用npm 安裝 PixiJS

npm install pixi.js --save

這邊要額外安裝 @types/offscreencanvasdevDependencies 否則會一直遇到下方奇怪的Error。

Error: node_modules/@pixi/core/index.d.ts:1543:45 - error TS2304: Cannot find name 'OffscreenCanvas'.`
Error: node_modules/@pixi/text/index.d.ts:272:41 - error TS2304: Cannot find name 'OffscreenCanvas'.`
Error: node_modules/@pixi/text/index.d.ts:273:49 - error TS2304: Cannot find name 'OffscreenCanvasRenderingContext2D'.
Error: node_modules/@pixi/text/index.d.ts:300:105 - error TS2304: Cannot find name 'OffscreenCanvas'.


npm install --save-dev @types/offscreencanvas  

angular.json

在這邊我們在 architect ➡️scripts 裡面加入 "./node_modules/pixi.js/dist/cjs/pixi.min.js"



tsconfig.json

在這邊要加入  "allowSyntheticDefaultImports": true 與    "types": [ "OffscreenCanvas"]   



這樣子照著官方的文件就可以正常跑出基礎教學的code.




Reference



留言