Aurelia Loader Webpack
raw JSON →Aurelia's loader implementation for webpack, enabling module loading and Hot Module Replacement (HMR) in Aurelia applications built with webpack. This package implements the Aurelia loader interface, allowing dynamic loading of modules, views, and resources. It supports Aurelia 2 (v2.x line, latest stable 2.2.5) with a universal bootstrapper and HMR capabilities, and is designed for use with webpack 4+. The library is actively maintained by the Aurelia team and provides compatibility with css-loader v4. It is part of the Aurelia ecosystem and should be used alongside aurelia-webpack-plugin. Key differentiators: native HMR support, eachModule iteration module, and caching of loading promises. Alternatives: aurelia-loader-nodejs for server-side rendering.
Common errors
error Error: Cannot find module 'aurelia-loader' ↓
error TypeError: aurelia.use.plugin is not a function ↓
error Module not found: Error: Can't resolve 'aurelia-loader-webpack' in ... ↓
Warnings
breaking Version 2.0.0 is a complete rewrite with a new universal bootstrapper and HMR support. It is not backward compatible with 1.x. ↓
gotcha When using css-loader v4, you may encounter compatibility issues. The fix was released in version 2.2.2. ↓
gotcha The eachModule iteration shortcircuits when the callback returns true. This may cause unexpected behavior if you don't expect return values to stop iteration. ↓
deprecated The export 'WebpackLoader' may be deprecated in future versions; prefer 'AureliaLoaderWebpack'. ↓
breaking Version 1.x relied on global 'window' for module resolution and lacked HMR. Upgrade to 2.x is required for HMR and modern webpack. ↓
Install
npm install aurelia-loader-webpack yarn add aurelia-loader-webpack pnpm add aurelia-loader-webpack Imports
- AureliaLoaderWebpack wrong
import AureliaLoaderWebpack from 'aurelia-loader-webpack';correctimport { AureliaLoaderWebpack } from 'aurelia-loader-webpack'; - Loader wrong
import { Loader } from 'aurelia-loader-webpack';correctimport { Loader } from 'aurelia-loader'; - WebpackLoader wrong
import { WebpackLoader } from 'aurelia-loader';correctimport { WebpackLoader } from 'aurelia-loader-webpack';
Quickstart
import { Aurelia } from 'aurelia-framework';
import { AureliaLoaderWebpack } from 'aurelia-loader-webpack';
import { PLATFORM } from 'aurelia-pal';
// In your Aurelia configuration file:
export function configure(aurelia: Aurelia): void {
aurelia.use
.standardConfiguration()
.developmentLogging();
// Register the webpack loader
aurelia.container.registerSingleton(Loader, AureliaLoaderWebpack);
aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('app')));
}