Skip to content

Latest commit

 

History

History
116 lines (97 loc) · 3.6 KB

File metadata and controls

116 lines (97 loc) · 3.6 KB

Ventus Library Modernization - Migration to Vite

Overview

Successfully modernized the Ventus window manager library from Webpack 4 to Vite 5, updating the build system, dependencies, and module format to use modern JavaScript tooling.

Major Changes Made

1. Build System Migration

  • Replaced Webpack 4 with Vite 5 for faster development and building
  • Removed old configuration files:
    • webpack.config.js
    • webpack.dev.config.js
    • webpack.prod.config.js
    • karma.conf.js (replaced with Vitest)
    • .babelrc (Vite handles transpilation natively)

2. Package.json Updates

  • Updated dependencies to modern versions:
    • Vite 5.4.10
    • Autoprefixer 10.4.20
    • ESLint 9.14.0
    • Less 4.2.0
    • PostCSS 8.4.47
    • Vitest 2.1.4
  • Removed outdated dependencies:
    • All Webpack-related packages
    • Babel packages (no longer needed)
    • Karma test runner packages
  • Added module exports configuration for both ESM and UMD builds
  • Updated scripts for modern development workflow

3. Module System Conversion

  • Converted all AMD modules to ES6 modules:
    • src/ventus/core/emitter.js
    • src/ventus/core/view.js
    • src/ventus/wm/window.js
    • src/ventus/wm/windowmanager.js
    • src/ventus/wm/modes/default.js
    • src/ventus/wm/modes/expose.js
  • Updated main entry point (src/ventus.js) to use ES6 export syntax
  • Fixed import paths for LESS files and dependencies

4. Configuration Files

  • Created vite.config.js with:
    • Library build configuration for UMD and ES module formats
    • LESS preprocessing support
    • PostCSS with autoprefixer integration
    • Source map generation
    • Terser minification
  • Updated postcss.config.js to use ES6 module syntax
  • Modernized .eslintrc for ES2022 and ES modules

5. Development Environment

  • Added index.html for development testing
  • Set up modern dev server with hot reloading
  • Configured proper alias resolution for internal modules

6. Testing Migration

  • Migrated from Karma/Mocha/Chai to Vitest
  • Updated test file (test/window.test.js) to use:
    • Modern ES6 import syntax
    • Vitest's expect API
    • Arrow functions instead of function expressions

Build Output

The modernized build generates:

  • dist/ventus.js - ES module build (32KB)
  • dist/ventus.umd.cjs - UMD build for legacy compatibility (18KB)
  • dist/style.css - Compiled LESS styles (9.6KB)
  • Source maps for debugging

Development Commands

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

# Run tests
npm test

# Run tests once
npm run test:run

# Lint code
npm run lint

Benefits of Modernization

  1. Faster development - Vite's dev server is significantly faster than Webpack
  2. Modern tooling - Updated to latest versions of all build tools
  3. Better tree shaking - ES modules enable better dead code elimination
  4. Improved DX - Hot module replacement and instant updates
  5. Future-proof - Uses modern JavaScript standards and tooling
  6. Smaller bundle size - More efficient bundling with Rollup
  7. Better debugging - Improved source maps and error reporting

Backward Compatibility

  • UMD build maintains compatibility with older module systems
  • Library API remains unchanged
  • Both CommonJS (require()) and ES modules (import) are supported

Status

Completed Successfully

  • Build system fully migrated to Vite
  • All modules converted to ES6
  • Development server working
  • Production builds generating correctly
  • Library maintains full functionality