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 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 vite

Configuration

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

Feature
Vite
Webpack
Parcel

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

  1. Install Vite and Aurelia plugin

  2. Move public/index.html to project root

  3. Update imports to use /src instead of relative paths

  4. Replace react-scripts commands with Vite commands

From Webpack to Vite

  1. Replace webpack configs with vite.config.js

  2. Update dev scripts to use vite instead of webpack-dev-server

  3. Convert webpack-specific features to Vite equivalents

  4. 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.splitChunks for better caching

  • Source Maps: Use 'source-map' for production debugging

  • Content 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.lazyCompilation and proper development aliases

  • For Vite: Ensure useDev: true is 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 experimentalTemplateTypeCheck in webpack loader options

Performance Tips

  1. Use development bundles: Always alias to .dev.mjs files during development

  2. Enable code splitting: Configure manual chunks for better loading performance

  3. Optimize assets: Use appropriate loaders for images, fonts, and other assets

  4. Source map strategy: Use eval-cheap-source-map for development, source-map for 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?