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.
7.9 KiB
Presentation layer
The presentation layer handles UI concerns using Vue as JavaScript framework and Electron to provide desktop functionality.
It reflects the application state and allows user interactions to modify it. Components manage their own local UI state.
The presentation layer uses an event-driven architecture for bidirectional reactivity between the application state and UI. State change events flow bottom-up to trigger UI updates, while user events flow top-down through components, some ultimately modifying the application state.
📖 Refer to architecture.md (Layered Application) to read more about the layered architecture.
Structure
/src/presentation/: Contains Vue and Electron code.bootstrapping/: Registers Vue components and plugins.components/: Contains Vue components and helpers.Shared/: Contains shared Vue components and helpers.hooks: Hooks used by components through dependency injection.
/public/: Contains static assets.assets/: Contains assets processed by Vite.fonts/: Contains fonts.styles/: Contains shared styles.components/: Contains styles for Vue components.vendors-extensions/: Contains styles for third-party components.main.scss: Main Sass file, imported by other components as single entrypoint.
main.ts: Starts Vue app.electron/: Contains Electron code.main.ts: Starts Electron app.
/vite.config.ts: Contains Vite configurations for building web application./postcss.config.cjs: Contains PostCSS configurations for Vite.
Visual design best-practices
Add visual clues for clickable items. It should be as clear as possible that they're interactable at first look without hovering. They should also have different visual state when hovering/touching on them that indicates that they are being clicked, which helps with accessibility.
Application data
Components (should) use UseApplication to reach the application domain to avoid parsing and compiling the application again.
Application.ts is an immutable domain model that represents application state. It includes:
- available scripts, collections as defined in collection files,
- package information as defined in
package.json.
You can read more about how application layer provides application data to he presentation in application.md | Application data.
Application state
This project uses a singleton instance of the application state, making it available to all Vue components.
The decision to not use third-party state management libraries like vuex or pinia was made to promote code independence and enhance portability.
Stateful components can mutate and/or react to state changes (e.g., user selection, search queries) in the ApplicationContext. Vue components import CollectionState.ts to access both the application context and the state.
UseCollectionState.ts provides several functionalities including:
- Singleton State Instance: It creates a singleton instance of the state, which is shared across the presentation layer. The singleton instance ensures that there's a single source of truth for the application's state.
- State Change Callback and Lifecycle Management: It offers a mechanism to register callbacks, which will be invoked when the state initializes or mutates. It ensures that components unsubscribe from state events when they are no longer in use or when ApplicationContext switches the active collection.
- State Access and Modification: It provides functions to read and mutate for accessing and modifying the state, encapsulating the details of these operations.
- Event Subscription Lifecycle Management: Includes an
eventsmember that simplifies state subscription lifecycle events. This ensures that components unsubscribe from state events when they are no longer in use, or when ApplicationContext switches the active collection.
📖 Refer to architecture.md | Application State for an overview of event handling and application.md | Application State for an in-depth understanding of state management in the application layer.
Dependency injections
The presentation layer uses Vue's native dependency injection system to increase testability and decouple components.
To add a new dependency:
- Define its symbol: Define an associated symbol for every dependency in
injectionSymbols.ts. Symbols are grouped into:- Singletons: Shared across components, instantiated once.
- Transients: Factories yielding a new instance on every access.
- Provide the dependency: Modify the
provideDependenciesfunction to include the new dependency.App.vuecalls this function within itssetup()hook to register the dependencies. - Inject the dependency: Use Vue's
injectmethod alongside the defined symbol to incorporate the dependency into components.- For singletons, invoke the factory method:
inject(symbolKey)(). - For transients, directly inject:
inject(symbolKey).
- For singletons, invoke the factory method:
Shared UI components
Shared UI components promote consistency and simplifies the creation of the front-end.
In order to maintain portability and easy maintainability, the preference is towards using homegrown components over third-party ones or comprehensive UI frameworks like Quasar.
Shared components include:
- ModalDialog.vue is utilized for rendering modal windows.
- TooltipWrapper.vue acts as a wrapper for rendering tooltips.
Desktop builds
Desktop builds uses electron-vite to bundle the code, and electron-builder to build and publish the packages.
Sass naming convention
- Use lowercase for variables/functions/mixins, e.g.:
- Variable:
$variable: value; - Function:
@function function() {} - Mixin:
@mixin mixin() {}
- Variable:
- Use - for a phrase/compound word, e.g.:
- Variable:
$some-variable: value; - Function:
@function some-function() {} - Mixin:
@mixin some-mixin() {}
- Variable:
- Grouping and name variables from generic to specific, e.g.:
- ✅
$border-blue,$border-blue-light,$border-blue-lightest,$border-red - ❌
$blue-border,$light-blue-border,$lightest-blue-border,$red-border
- ✅