Migrate web builds from Vue CLI to Vite
This commit changes the web application's build, transpilation and minification process from Vue CLI to Vite. This shift paves the way for a full migration to Vite as the primary build tool (#230). Configuration changes: - `.vscode/extensions.json`: Update recommended plugins, replacing unmaintained ones with official recommendations. - Legacy browser support: - Use `@vitejs/plugin-legacy` to transpile for older browsers. - Remove `core-js` dependency and `babel.config.cjs` configuration as they're now handled by the legacy plugin. - Delete `@babel/preset-typescript` and `@babel/preset-typescript` dependencies as legacy plugin handles babel dependencies by default. - Add `terser` dependency that's used by the legacy plugin for minification, as per Vite's official documentation. - `tsconfig.json`: - Remove obsolete `webpack-env` types. - Add `"resolveJsonModule": true` to be able to read JSON files in right way. - Use correct casing as configuration values. - Simplify `lib` to align with Vite and Vue starter configuration. - Add `"skipLibCheck": true` as `npm run build` now runs `tsc` which fails on inconsistent typings inside `node_modules` due to npm's weak dependency resoultion. - PostCSS: - Add `autoprefixer` as dependency, no longer installed by Vue CLI. - Epxlicitly added `postcss` as dependency to anticipate potential peer dependency changes. - Remove related `@vue/cli` dependencies. - Remove `sass-loader` as Vite has native CSS preprocessing support. - Run integration tests with `jsdom` environment so `window` object can be used. Client-side changes: - Abstract build tool specific environment variable population. Environment variables were previously populated by Vue CLI and now by Vite but not having an abstraction caused issues. This abstraction solves build errors and allows easier future migrations and testing. - Change Vue CLI-specific `~@` aliases to `@` to be able to compile with Vite. - Update types in LiquorTree to satisfy `tsc`. - Remove Vue CLI-specific workaround from `src/presentation/main.ts`. Restructuring: - Move `public/` to `presentation/` to align with the layered structure, which was not possible with Vue CLI. - Move `index.html` to web root instead of having it inside `public/` to align with official recommended structure. - Move logic shared by both integration and unit tests to `tests/shared`. - Move logo creation script to `scripts/` and its npm command to include `build` to align with rest of the structure.
This commit is contained in:
13
src/infrastructure/Metadata/IAppMetadata.ts
Normal file
13
src/infrastructure/Metadata/IAppMetadata.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Represents essential metadata about the application.
|
||||
*
|
||||
* Designed to decouple the process of retrieving metadata
|
||||
* (e.g., from the build environment) from the rest of the application.
|
||||
*/
|
||||
export interface IAppMetadata {
|
||||
readonly version: string;
|
||||
readonly name: string;
|
||||
readonly slogan: string;
|
||||
readonly repositoryUrl: string;
|
||||
readonly homepageUrl: string;
|
||||
}
|
||||
29
src/infrastructure/Metadata/Vite/ViteAppMetadata.ts
Normal file
29
src/infrastructure/Metadata/Vite/ViteAppMetadata.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { IAppMetadata } from '../IAppMetadata';
|
||||
|
||||
/**
|
||||
* Provides the application's metadata using Vite's environment variables.
|
||||
*/
|
||||
export class ViteAppMetadata implements IAppMetadata {
|
||||
// Ensure the use of import.meta.env prefix for the following properties.
|
||||
// Vue will replace these statically during production builds.
|
||||
|
||||
public get version(): string {
|
||||
return import.meta.env.VITE_APP_VERSION;
|
||||
}
|
||||
|
||||
public get name(): string {
|
||||
return import.meta.env.VITE_APP_NAME;
|
||||
}
|
||||
|
||||
public get slogan(): string {
|
||||
return import.meta.env.VITE_APP_SLOGAN;
|
||||
}
|
||||
|
||||
public get repositoryUrl(): string {
|
||||
return import.meta.env.VITE_APP_REPOSITORY_URL;
|
||||
}
|
||||
|
||||
public get homepageUrl(): string {
|
||||
return import.meta.env.VITE_APP_HOMEPAGE_URL;
|
||||
}
|
||||
}
|
||||
8
src/infrastructure/Metadata/Vite/ViteEnvironmentKeys.ts
Normal file
8
src/infrastructure/Metadata/Vite/ViteEnvironmentKeys.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// Only variables prefixed with VITE_ are exposed to Vite-processed code
|
||||
export const VITE_ENVIRONMENT_KEYS = {
|
||||
VERSION: 'VITE_APP_VERSION',
|
||||
NAME: 'VITE_APP_NAME',
|
||||
SLOGAN: 'VITE_APP_SLOGAN',
|
||||
REPOSITORY_URL: 'VITE_APP_REPOSITORY_URL',
|
||||
HOMEPAGE_URL: 'VITE_APP_HOMEPAGE_URL',
|
||||
} as const;
|
||||
11
src/infrastructure/Metadata/Vite/vite-env.d.ts
vendored
Normal file
11
src/infrastructure/Metadata/Vite/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
import { VITE_ENVIRONMENT_KEYS } from './ViteEnvironmentKeys';
|
||||
|
||||
export type ViteEnvironmentVariables = {
|
||||
readonly [K in keyof typeof VITE_ENVIRONMENT_KEYS]: string;
|
||||
};
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ViteEnvironmentVariables
|
||||
}
|
||||
Reference in New Issue
Block a user