Modern Build Tools
Modern build tool configuration for Aurelia 2, featuring Vite, Webpack, and Parcel with official plugins and optimal development experience.
Aurelia 2 provides official support for modern build tools that offer fast development servers, optimized builds, and excellent developer experience. Choose the tool that best fits your project needs and team preferences.
Quick Start Recommendations
π New Projects: Use Vite for fastest development and modern features
π’ Enterprise/Existing: Use Webpack for maximum configurability and ecosystem
β‘ Simple Projects: Use Parcel for zero-config builds
Vite (Recommended)
Vite provides lightning-fast development with instant hot module replacement and optimized production builds. Recommended for new projects.
Why Vite?
β‘ Instant server start and HMR
π― Modern ES modules in development
π¦ Optimized Rollup builds for production
π§ Minimal configuration required
Installation
npm install -D @aurelia/vite-plugin viteConfiguration
Create vite.config.js:
TypeScript Support
For TypeScript projects, add this type declaration file:
src/html.d.ts (auto-generated by Aurelia CLI):
Advanced Vite Configuration
Webpack
Webpack offers maximum configurability and is well-suited for complex applications with specific build requirements.
Installation
Basic Configuration
Create webpack.config.js:
Production Configuration
Create webpack.prod.js for optimized builds:
Parcel
Parcel offers zero-configuration bundling with excellent performance and modern features out of the box.
Installation
Configuration
Create .parcelrc:
Optional Package.json Configuration
Add Aurelia-specific options to package.json:
TypeScript Support
Add the same html.d.ts file as shown in the Vite section.
Tool Comparison
Development Speed
β‘ Fastest
π‘ Moderate
β‘ Fast
Production Builds
π― Excellent
π― Excellent
π― Good
Configuration
π’ Minimal
π΄ Complex
π’ Zero-config
Ecosystem
π‘ Growing
π― Mature
π‘ Good
Hot Reload
β‘ Instant
π‘ Good
β‘ Fast
Bundle Analysis
π’ Built-in
π― Excellent
π‘ Basic
Learning Curve
π’ Easy
π΄ Steep
π’ Easy
Common Development Patterns
Environment Variables
Vite:
Webpack:
CSS Processing
Vite with PostCSS:
Webpack with PostCSS:
Asset Handling
All bundlers automatically handle common assets:
Performance Optimization
Bundle Splitting
Vite:
Webpack:
Tree Shaking
All modern bundlers automatically tree-shake unused code. Ensure your imports are ES module compatible:
Migration Between Tools
From Create React App to Vite
Install Vite and Aurelia plugin
Move
public/index.htmlto project rootUpdate imports to use
/srcinstead of relative pathsReplace
react-scriptscommands with Vite commands
From Webpack to Vite
Replace webpack configs with
vite.config.jsUpdate dev scripts to use
viteinstead ofwebpack-dev-serverConvert webpack-specific features to Vite equivalents
Test that all dynamic imports still work
Troubleshooting
Common Issues
Vite: "Failed to resolve import"
Webpack: "Module not found"
Parcel: "Cannot resolve dependency"
Development vs Production Differences
Development: Use source maps, hot reload, and unminified code
Production: Enable minification, tree shaking, and bundle splitting
Testing: Consider using the same bundler for tests to catch bundler-specific issues
Next Steps
Choose your preferred build tool and start building amazing Aurelia applications! const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = function(env, { mode }) { const production = mode === 'production';
return { target: 'web', mode: production ? 'production' : 'development', devtool: production ? 'source-map' : 'eval-cheap-source-map', entry: { app: './src/main.ts' }, output: { path: path.resolve(__dirname, 'dist'), filename: production ? '[name].[contenthash].bundle.js' : '[name].bundle.js' }, resolve: { extensions: ['.ts', '.js'], modules: [path.resolve(__dirname, 'src'), 'node_modules'] }, devServer: { historyApiFallback: true, open: !process.env.CI, port: 9000 }, module: { rules: [ // Asset loaders { test: /.(png|gif|jpg|cur)$/i, loader: 'url-loader', options: { limit: 8192 } }, { test: /.woff2(?v=[0-9].[0-9].[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff2' } }, { test: /.woff(?v=[0-9].[0-9].[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff' } }, { test: /.(ttf|eot|svg|otf)(?v=[0-9].[0-9].[0-9])?$/i, loader: 'file-loader' },
}; };
Hot Module Replacement (HMR)
To enable HMR for Aurelia components:
TypeScript Type Checking
For enhanced TypeScript support with template type checking:
Production Optimizations
Minification: Webpack 5+ includes Terser plugin by default for production builds
Code Splitting: Configure
optimization.splitChunksfor better cachingSource Maps: Use
'source-map'for production debuggingContent Hashing: Use
[contenthash]in filenames for long-term caching
Vite
Vite is a fast, modern bundler (and dev server) that works excellently with Aurelia. Its plugin system provides quick project startup, HMR (Hot Module Replacement), and speedy builds.
Installing
Basic Usage
In vite.config.js:
TypeScript Support
For TypeScript apps, add this declaration file to your project (usually generated by the Aurelia CLI):
html.d.ts
Plugin Configuration Options
The Aurelia Vite plugin accepts several configuration options:
Development Configuration
By default, the Aurelia Vite plugin automatically uses development bundles when in development mode:
Production & Code Splitting
Vite automatically optimizes for production. You can customize chunk splitting:
Source Maps and Debugging
Parcel
Parcel is a zero-configuration bundler that works well with Aurelia 2 through the official transformer.
Installing
Configuration
Create a .parcelrc file in your project root:
For JavaScript projects:
Package.json Configuration
You can configure Aurelia-specific options in your package.json:
TypeScript Support
For TypeScript projects, add the same html.d.ts declaration file mentioned in the Vite section.
CSS and Styling
CSS Modules
Aurelia supports CSS modules with proper bundler configuration:
SCSS/SASS Support
Add SASS loaders for SCSS support:
Troubleshooting
Common Issues
"Cannot resolve module" errors
Ensure file extensions are properly configured in bundler resolve settings
Check that Aurelia loaders are properly configured for HTML and TypeScript files
Slow development builds
For Webpack: Enable
experiments.lazyCompilationand proper development aliasesFor Vite: Ensure
useDev: trueis set in the Aurelia plugin options
HMR not working
Verify HMR is enabled in both bundler and Aurelia loader configurations
Check browser console for HMR-related warnings
TypeScript template errors
Ensure proper HTML type definitions are included
Consider enabling
experimentalTemplateTypeCheckin webpack loader options
Performance Tips
Use development bundles: Always alias to
.dev.mjsfiles during developmentEnable code splitting: Configure manual chunks for better loading performance
Optimize assets: Use appropriate loaders for images, fonts, and other assets
Source map strategy: Use
eval-cheap-source-mapfor development,source-mapfor production
Conclusion
Aurelia 2 provides excellent bundler flexibility through dedicated loaders and plugins. Vite offers the fastest development experience with minimal configuration, while Webpack provides maximum customization options. Parcel offers a good middle ground with zero-configuration setup.
Key points to remember:
Always use the official Aurelia bundler plugins/loaders
Configure proper TypeScript declarations for HTML modules
Use development bundles during development for better debugging
Enable HMR for the best development experience
For advanced configurations and bundler-specific optimizations, refer to the official documentation of your chosen bundler alongside Aurelia's guides.
Last updated
Was this helpful?