Front-end Build System with Vite
June 7, 2025 ยท View on GitHub
This project uses Vite as a front-end build system to process CSS and JavaScript files.
Directory Structure
src/css/: Contains the source CSS filessrc/js/: Contains the source JavaScript filespublic/dist/: Contains the built files (generated by Vite)
Development
To start the development server:
npm run dev
This will start a development server at http://localhost:5173/ that will automatically reload when you make changes to the source files.
Building for Production
To build the assets for production:
npm run build
This will generate optimized files in the public/dist/ directory.
How It Works
- The source files are located in the
src/directory. - Vite processes these files and outputs them to the
public/dist/directory. - The
ViteHelperclass inapp/Helpers/ViteHelper.phphandles loading the correct assets in the views. - In development mode, assets are loaded from the Vite development server.
- In production mode, assets are loaded from the
public/dist/directory.
Adding New Assets
- Add new CSS files to
src/css/ - Add new JavaScript files to
src/js/ - Update the
vite.config.jsfile to include the new files in theinputobject - Import CSS files in JavaScript files using
import '../css/your-file.css' - Use the
vite_tags()helper function in views to load the assets
Updating jQuery
Currently, jQuery is loaded separately from the Vite build system. To include it in the build system:
-
Install jQuery using npm:
npm install jquery -
Import jQuery in your JavaScript files:
import $ from 'jquery'; -
Update the views to remove the separate jQuery script tag