The extension system is a core architecture of PixiJS that enables modularity, flexibility, and extensibility. Every major system in PixiJS is implemented as an extension, from rendering pipelines to asset loading.
Register an extension using the global extensions
object:
import { extensions, ExtensionType } from 'pixi.js';
const customLoader = {
extension: {
type: ExtensionType.LoadParser,
name: 'custom-loader',
priority: 100, // Optional priority for ordering
},
test(url: string) {
return url.endsWith('.custom');
},
load(url: string) {
// Custom loading logic
return fetch(url).then(/* ... */);
},
};
extensions.add(customLoader);
// Add single extension
extensions.add(customLoader);
// Add multiple extensions
extensions.add(customLoader, customSystem, customPlugin);
// Remove single extension
extensions.remove(customLoader);
// Remove multiple extensions
extensions.remove(customLoader, customSystem);
Extensions can specify a priority to control their order of execution:
const highPriorityLoader = {
extension: {
type: ExtensionType.LoadParser,
name: 'priority-loader',
priority: 100, // Higher priority runs first
},
};
const lowPriorityLoader = {
extension: {
type: ExtensionType.LoadParser,
name: 'fallback-loader',
priority: -1, // Lower priority runs last
},
};
Asset management extensions handle loading, resolving, caching, and detecting assets. They can be combined into a single asset group extension.
// Asset group extension
const assetBundle = {
extension: {
type: ExtensionType.Asset,
name: 'bundle-loader',
},
load: {
/* loader config */
},
resolve: {
/* resolver config */
},
cache: {
/* cache config */
},
detection: {
/* detection config */
},
};
Rendering extensions define how objects are rendered, including systems and pipes. They can be WebGL or WebGPU based.
// Renderer system extension
class CustomSystem {
static extension = {
type: [ExtensionType.WebGLSystem, ExtensionType.WebGPUSystem],
name: 'custom-system',
};
init() {
/* ... */
}
destroy() {
/* ... */
}
}
// Render pipe extension
const customPipe = {
extension: {
type: ExtensionType.WebGLPipes,
name: 'custom-pipe',
},
render(object) {
/* ... */
},
};
Application plugins extend the core application functionality, allowing for custom features and behaviors.
class CustomPlugin {
static extension = {
type: ExtensionType.Application,
name: 'custom-plugin',
};
static init(options) {
// Add features to Application
Object.defineProperty(this, 'customFeature', {
value: () => console.log('Custom feature!'),
});
}
static destroy() {
// Cleanup
}
}
ExtensionType.Application
: Application pluginsExtensionType.Environment
: Environment configurationExtensionType.Asset
: Combined asset handlingExtensionType.LoadParser
: Resource loadingExtensionType.ResolveParser
: URL resolutionExtensionType.CacheParser
: Cache managementExtensionType.DetectionParser
: Format detectionExtensionType.WebGLSystem
: WebGL systemsExtensionType.WebGPUSystem
: WebGPU systemsExtensionType.CanvasSystem
: Canvas systemsExtensionType.WebGLPipes
: WebGL render pipesExtensionType.WebGPUPipes
: WebGPU render pipesExtensionType.CanvasPipes
: Canvas render pipesExtensionType.MaskEffect
: Custom maskingExtensionType.BlendMode
: Blend modesExtensionType.TextureSource
: Texture handlingExtensionType.ShapeBuilder
: Graphics shapesExtensionType.Batcher
: Render batchingFor detailed implementation requirements and advanced usage, refer to the API documentation of individual extension types.