Webpack
The Aurelia CLI offers full support for Webpack as a bundler, suitable for both ESNext and TypeScript applications.
PLATFORM.moduleName
When referencing modules by string in a Webpack-configured Aurelia application, wrap the module names using PLATFORM.moduleName. This informs Webpack about Aurelia's dynamic loading behavior.
Example:
// src/resources/index.js
import { PLATFORM } from 'aurelia-framework';
export function configure(config) {
config.globalResources([
PLATFORM.moduleName('./elements/my-awesome-element')
]);
}
// router configuration
export function configureRouter(config, router) {
this.router = router;
config.map([
{
route: '',
name: 'home',
title: 'Home',
nav: true,
moduleId: PLATFORM.moduleName('./home')
}
]);
}Hint: The aurelia-webpack-plugin processes PLATFORM.moduleName, bridging Webpack with Aurelia's dynamic behavior.
Running the Application
To run your Aurelia application with Webpack:
Common Flags:
--hmr: Enables Hot Module Reload.--analyze: Opens the Webpack Bundle Analyzer.
Configuration:
Default settings for au run are located in the platform section of aurelia.json:
Adjust settings like hmr, open, and port as needed.
Simplified Webpack
From Aurelia CLI v1.1.0 onwards, Webpack usage has been simplified:
Decoupled Bundler: Webpack operates independently from the CLI's task files.
Commands:
au runmaps tonpm start.au buildmaps tonpm run build:dev.
Environment Configuration:
Environment files are located in the config/ folder, managed by the app-settings-loader Webpack plugin.
Deploying Your App
To prepare your application for deployment:
Create a Production Build:
Deployment Output:
Non-ASP.NET Core: Contents reside in the
distfolder. Copy this to your web server.ASP.NET Core: Build output is located in
wwwroot/dist. Deploy the ASP.NET Core application as per Microsoft Docs.
Build Options
Webpack configurations are exported as functions based on parameters:
These parameters are influenced by the build.options in aurelia.json:
Production Flag: Determined by the
--envflag (prodfor production builds).
Installing 3rd Party Dependencies
Webpack intelligently bundles 3rd party dependencies. To install a new dependency:
Unit Testing
Depending on your setup during au new, you may have one of the following test runners:
Jest:
Karma:
Protractor:
Ensure
npsis installed globally:
ASP.NET Core
When integrating with ASP.NET Core:
Set Environment Variable:
Refer to Microsoft Docs for detailed instructions.
Configure Project:
Use Visual Studio to create the ASP.NET Core project.
Integrate Aurelia using
au new --herewithin the project directory.
Hint: Prevent Visual Studio from compiling TypeScript by adding <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> to your .xproj file.
Last updated
Was this helpful?