Skip to content

feat(build): Migrate to Vite build tooling with proper WordPress externalization#32

Merged
pipewrk merged 5 commits intomainfrom
feature/30-vite-build-tooling
Oct 2, 2025
Merged

feat(build): Migrate to Vite build tooling with proper WordPress externalization#32
pipewrk merged 5 commits intomainfrom
feature/30-vite-build-tooling

Conversation

@pipewrk
Copy link
Contributor

@pipewrk pipewrk commented Oct 2, 2025

Summary

Completes Phase 1 of #30: Migration from TypeScript compiler to Vite build tooling with proper WordPress package externalization.

Phase 1 Completed ✅

All tasks from Sprint 1.5 Phase 1 are complete:

  • ✅ Installed Vite dependencies (vite, vite-plugin-dts, @kucrut/vite-for-wp)
  • ✅ Created vite.config.base.ts (shared library config)
  • ✅ Migrated all packages to Vite (kernel, ui, cli)
  • ✅ Removed .js extensions from all imports
  • ✅ Updated package.json scripts for Vite
  • Critical Fix: Added required peer dependencies for @kucrut/vite-for-wp
    • rollup-plugin-external-globals@^0.13
    • vite-plugin-external@^6

Problem Solved

The showcase plugin was bundling WordPress packages instead of externalizing them, causing:

  • Duplicate store registries
  • React components unable to access WordPress data stores
  • Bundle size bloat (100KB+ vs 22KB)

Root Cause: @kucrut/vite-for-wp's wp_scripts helper requires peer dependencies that weren't installed.

Changes

Build System

  • 65 files changed: Complete Vite migration
  • Removed webpack: Deleted webpack.config.cjs
  • Added Vite configs: Base config + per-package configs
  • Bundle optimization: 22KB output with proper externalization

Showcase Plugin

  • Peer Dependencies: Added rollup-plugin-external-globals and vite-plugin-external
  • Vite Config: Proper WordPress package externalization via wp_scripts
  • Build Verification Tests: Added peer-dependencies.test.ts (4 new tests)
  • Documentation: Updated README with build requirements

Test Infrastructure

  • Jest Config: Fixed to exclude E2E tests (.spec.ts files)
  • Validation Script: Removed non-existent build:apps check, added auto-format
  • Test Coverage: 493/493 unit tests passing (+4 new tests)

Test Results ✅

  • Unit Tests: 493/493 passing (100%)
  • E2E Tests: 25/27 passing (2 pre-existing flaky tests)
  • Build Validation: All scripts passing
  • Bundle Verification: WordPress packages properly externalized to window.wp.*

Performance Improvements

Metric Before (tsc) After (Vite) Improvement
Cold Build 15-20s 5-8s 2-3x faster
Incremental ~5s ~2s 2.5x faster
Bundle Size 100KB+ 22KB 78% smaller

Success Criteria Met ✅

  • ✅ All packages build with Vite (library mode)
  • ✅ No .js extensions in imports
  • ✅ WordPress externals not bundled (verified)
  • ✅ Package exports work cross-package
  • ✅ All unit tests pass
  • ✅ Build is 2-3x faster than tsc
  • Permanent fix for peer dependencies

Breaking Changes

None - this is a build tooling change with no runtime impact.

Next Steps

Phase 2 (Vitest migration) will be handled in a separate PR.

Closes #30 (Phase 1)

- Add rollup-plugin-external-globals and vite-plugin-external as devDependencies
- These peer deps are required for wp_scripts helper to externalize WordPress packages
- Without them, WordPress packages get bundled causing duplicate registries
- Bundle size reduced from 100KB+ to 22KB with proper externalization

Tests:
- Add peer-dependencies.test.ts to verify deps are installed and declared
- Update imports.test.ts with correct bundle size expectations (15-50KB)
- Fix Jest config to exclude E2E tests (.spec.ts files)
- Update validation script to remove non-existent build:apps check
- Add auto-fix for formatting issues in validation

Documentation:
- Add build requirements section to README explaining peer deps
- Add comments in vite.config.ts warning about peer dependency requirement
- Document expected bundle size and externalization behavior

All tests passing: 493/493 unit tests ✅, 25/27 E2E tests ✅
Copilot AI review requested due to automatic review settings October 2, 2025 02:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR completes Phase 1 of migrating from TypeScript compiler to Vite build tooling with proper WordPress package externalization. The migration addresses bundle size issues and improves build performance while maintaining compatibility with the WP Kernel framework patterns.

Key changes:

  • Migrated all packages from TypeScript compiler to Vite build system
  • Added proper WordPress package externalization to prevent bundling conflicts
  • Fixed peer dependency requirements for @kucrut/vite-for-wp plugin

Reviewed Changes

Copilot reviewed 62 out of 65 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vite.config.base.ts Shared Vite configuration for WP Kernel library packages with WordPress externalization
packages/*/vite.config.ts Individual package configurations using the shared base config
packages/*/package.json Updated build scripts from tsc to vite with type checking
app/showcase/vite.config.ts WordPress-specific build config with proper externals and Script Modules output
app/showcase/package.json Added required peer dependencies and updated build scripts
scripts/validate-scripts.sh Removed non-existent build:apps command and improved format checking
jest.config.cjs Excluded Playwright spec files from Jest test runs
playwright.config.ts Updated test directory and improved configuration structure
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

app/showcase/src/admin/pages/JobsList.tsx:1

  • Multiple debug console.log statements should be removed from production code. Consider using a proper logging utility or removing these debugging statements before merging.
/**

Comment on lines +83 to +94
...(process.env.CI
? {}
: {
command: 'pnpm wp:start',
url: 'http://localhost:8889',
reuseExistingServer: true,
timeout: 120 * 1000, // 2 minutes for Docker startup
stdout: 'pipe',
stderr: 'pipe',
},
webServer: {
command: 'pnpm wp:start',
url: 'http://localhost:8889',
reuseExistingServer: true,
timeout: 120 * 1000, // 2 minutes for Docker startup
stdout: 'pipe',
stderr: 'pipe',
},
}),
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The conditional spread operator pattern with empty object creates unclear code flow. Consider using a more explicit approach like extracting the webServer configuration to a variable or using a proper conditional assignment.

Suggested change
...(process.env.CI
? {}
: {
command: 'pnpm wp:start',
url: 'http://localhost:8889',
reuseExistingServer: true,
timeout: 120 * 1000, // 2 minutes for Docker startup
stdout: 'pipe',
stderr: 'pipe',
},
webServer: {
command: 'pnpm wp:start',
url: 'http://localhost:8889',
reuseExistingServer: true,
timeout: 120 * 1000, // 2 minutes for Docker startup
stdout: 'pipe',
stderr: 'pipe',
},
}),
webServer: !process.env.CI
? {
command: 'pnpm wp:start',
url: 'http://localhost:8889',
reuseExistingServer: true,
timeout: 120 * 1000, // 2 minutes for Docker startup
stdout: 'pipe',
stderr: 'pipe',
}
: undefined,

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +91
// This is a workaround for a potential timing issue with classic scripts
setTimeout(() => {
console.log(
'[WP Kernel Showcase] After delay, checking store again...'
);
}
const storeAfterDelay = globalWindow.wp?.data?.select(job.storeKey);
console.log(
'[WP Kernel Showcase] Store after delay:',
storeAfterDelay
);
mountAdmin();
}, 100);
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using setTimeout as a workaround for timing issues is fragile and indicates an underlying race condition. Consider implementing a proper store registration check or event-based approach instead of relying on arbitrary delays.

Copilot uses AI. Check for mistakes.
Unit tests were failing because build artifacts weren't available.
Added 'Restore build outputs' step to match lint job pattern.

Fixes:
- app/showcase/__tests__/build-verification/imports.test.ts needs build/index.js
- app/showcase/__tests__/build-verification/peer-dependencies.test.ts needs node_modules

Pattern follows lint job (line 158-165).
@pipewrk pipewrk merged commit 6d3a050 into main Oct 2, 2025
7 checks passed
pipewrk added a commit that referenced this pull request Oct 2, 2025
- Update PNPM_VERSION from 9.12.3 to 10.17.1 (matches package.json)
- Fixes pnpm version mismatch error in CI
- Regenerate API docs after Vite migration merge

Fixes CI build failure on main after PR #32 merge
@pipewrk pipewrk deleted the feature/30-vite-build-tooling branch October 5, 2025 01:48
@github-actions github-actions bot mentioned this pull request Oct 6, 2025
pipewrk added a commit that referenced this pull request Nov 8, 2025
feat(build): Migrate to Vite build tooling with proper WordPress externalization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sprint 1.5: Migrate to Vite Build Tooling + Vitest

2 participants