├── phpstan.neon ├── ecs.php ├── src ├── translations │ └── en │ │ └── vite.php ├── services │ ├── ServicesTrait.php │ └── Helper.php ├── variables │ └── ViteVariable.php ├── helpers │ └── PluginConfig.php ├── icon.svg ├── config.php ├── models │ └── Settings.php └── Vite.php ├── Makefile ├── LICENSE.md ├── composer.json ├── README.md └── CHANGELOG.md /phpstan.neon: -------------------------------------------------------------------------------- 1 | includes: 2 | - %currentWorkingDirectory%/vendor/craftcms/phpstan/phpstan.neon 3 | 4 | parameters: 5 | level: 5 6 | paths: 7 | - src 8 | -------------------------------------------------------------------------------- /ecs.php: -------------------------------------------------------------------------------- 1 | paths([ 8 | __DIR__ . '/src', 9 | __FILE__, 10 | ]); 11 | $ecsConfig->parallel(); 12 | $ecsConfig->sets([SetList::CRAFT_CMS_4]); 13 | }; 14 | -------------------------------------------------------------------------------- /src/translations/en/vite.php: -------------------------------------------------------------------------------- 1 | 'Vite Cache', 18 | '{name} plugin loaded' => '{name} plugin loaded', 19 | ]; 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | MAJOR_VERSION?=5 2 | PLUGINDEV_PROJECT_DIR?=/Users/andrew/webdev/sites/plugindev/cms_v${MAJOR_VERSION}/ 3 | VENDOR?=nystudio107 4 | PROJECT_PATH?=${VENDOR}/$(shell basename $(CURDIR)) 5 | 6 | .PHONY: dev docs release 7 | 8 | # Start up the buildchain dev server 9 | dev: 10 | # Start up the docs dev server 11 | docs: 12 | ${MAKE} -C docs/ dev 13 | # Run code quality tools, tests, and build the buildchain & docs in preparation for a release 14 | release: --code-quality --code-tests --buildchain-clean-build --docs-clean-build 15 | # The internal targets used by the dev & release targets 16 | --buildchain-clean-build: 17 | --code-quality: 18 | ${MAKE} -C ${PLUGINDEV_PROJECT_DIR} -- ecs check vendor/${PROJECT_PATH}/src --fix 19 | ${MAKE} -C ${PLUGINDEV_PROJECT_DIR} -- phpstan analyze -c vendor/${PROJECT_PATH}/phpstan.neon 20 | --code-tests: 21 | --docs-clean-build: 22 | ${MAKE} -C docs/ clean 23 | ${MAKE} -C docs/ image-build 24 | ${MAKE} -C docs/ fix 25 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) nystudio107 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nystudio107/craft-vite", 3 | "description": "Allows the use of the Vite.js next generation frontend tooling with Craft CMS", 4 | "type": "craft-plugin", 5 | "version": "5.0.1", 6 | "keywords": [ 7 | "craft", 8 | "cms", 9 | "craftcms", 10 | "craft-plugin", 11 | "vite" 12 | ], 13 | "support": { 14 | "docs": "https://nystudio107.com/docs/vite/", 15 | "issues": "https://nystudio107.com/plugins/vite/support", 16 | "source": "https://github.com/nystudio107/craft-vite" 17 | }, 18 | "license": "MIT", 19 | "authors": [ 20 | { 21 | "name": "nystudio107", 22 | "homepage": "https://nystudio107.com" 23 | } 24 | ], 25 | "require": { 26 | "php": "^8.2", 27 | "craftcms/cms": "^5.0.0", 28 | "nystudio107/craft-plugin-vite": "^5.0.2" 29 | }, 30 | "require-dev": { 31 | "craftcms/cloud": "^2.0.0", 32 | "craftcms/ecs": "dev-main", 33 | "craftcms/phpstan": "dev-main", 34 | "craftcms/rector": "dev-main" 35 | }, 36 | "scripts": { 37 | "phpstan": "phpstan --ansi --memory-limit=1G", 38 | "check-cs": "ecs check --ansi", 39 | "fix-cs": "ecs check --fix --ansi" 40 | }, 41 | "config": { 42 | "allow-plugins": { 43 | "craftcms/plugin-installer": true, 44 | "yiisoft/yii2-composer": true 45 | }, 46 | "optimize-autoloader": true, 47 | "sort-packages": true 48 | }, 49 | "autoload": { 50 | "psr-4": { 51 | "nystudio107\\vite\\": "src/" 52 | } 53 | }, 54 | "extra": { 55 | "changelogUrl": "https://raw.githubusercontent.com/nystudio107/craft-vite/v5/CHANGELOG.md", 56 | "class": "nystudio107\\vite\\Vite", 57 | "handle": "vite", 58 | "name": "Vite" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nystudio107/craft-vite/badges/quality-score.png?b=v5)](https://scrutinizer-ci.com/g/nystudio107/craft-vite/?branch=v5) [![Code Coverage](https://scrutinizer-ci.com/g/nystudio107/craft-vite/badges/coverage.png?b=v5)](https://scrutinizer-ci.com/g/nystudio107/craft-vite/?branch=v5) [![Build Status](https://scrutinizer-ci.com/g/nystudio107/craft-vite/badges/build.png?b=v5)](https://scrutinizer-ci.com/g/nystudio107/craft-vite/build-status/v5) [![Code Intelligence Status](https://scrutinizer-ci.com/g/nystudio107/craft-vite/badges/code-intelligence.svg?b=v5)](https://scrutinizer-ci.com/code-intelligence) 2 | 3 | # Vite plugin for Craft CMS 5.x 4 | 5 | Allows the use of the Vite.js next generation frontend tooling with Craft CMS 6 | 7 | ![Screenshot](./docs/docs/resources/img/plugin-logo.png) 8 | 9 | Related Article: [Vite.js Next Generation Frontend Tooling + Craft CMS](https://nystudio107.com/blog/using-vite-js-next-generation-frontend-tooling-with-craft-cms) 10 | 11 | Most of the magic is actually in the [nystudio107/craft-plugin-vite](https://github.com/nystudio107/craft-plugin-vite) package, so that Craft CMS plugins can use it too. 12 | 13 | ## Requirements 14 | 15 | This plugin requires Craft CMS 5.0.0 or later. 16 | 17 | **Installation** 18 | 19 | 1. Install with Composer via `composer require nystudio107/craft-vite` from your project directory 20 | 2. Install the plugin via `php craft install/plugin vite` via the CLI -or- in the Craft Control Panel under Settings > Plugins 21 | 22 | You can also install Vite via the **Plugin Store** in the Craft Control Panel. 23 | 24 | ## Documentation 25 | 26 | Click here -> [Vite Documentation](https://nystudio107.com/plugins/vite/documentation) 27 | 28 | Brought to you by [nystudio107](http://nystudio107.com) 29 | -------------------------------------------------------------------------------- /src/services/ServicesTrait.php: -------------------------------------------------------------------------------- 1 | [ 38 | 'helper' => HelperService::class, 39 | 'vite' => PluginConfigHelper::serviceDefinitionFromConfig('vite', ViteService::class), 40 | ], 41 | ]; 42 | } 43 | 44 | // Public Methods 45 | // ========================================================================= 46 | 47 | /** 48 | * Returns the helper service 49 | * 50 | * @return HelperService The helper service 51 | * @throws InvalidConfigException 52 | */ 53 | public function getHelper(): HelperService 54 | { 55 | return $this->get('helper'); 56 | } 57 | 58 | /** 59 | * Returns the vite service 60 | * 61 | * @return ViteService The helper service 62 | * @throws InvalidConfigException 63 | */ 64 | public function getVite(): ViteService 65 | { 66 | return $this->get('vite'); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Vite Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | ## 5.0.1 - 2024.08.13 6 | ### Added 7 | * Added a `craft.vite.integrity()` method that will extract the integrity hash (for building a Content Security Policy) 8 | * Added an `includeScriptOnloadHandler` config setting that allows you to disable the adding of an `onload` handler on the `