├── src
├── web
│ └── assets
│ │ ├── Dockerfile
│ │ ├── dist
│ │ ├── react-refresh-shim.min.js
│ │ ├── safari-nomodule-fix.min.js
│ │ └── modulepreload-polyfill.min.js
│ │ ├── src
│ │ ├── react-refresh-shim.js
│ │ ├── safari-nomodule-fix.js
│ │ └── modulepreload-polyfill.js
│ │ ├── package.json
│ │ ├── Makefile
│ │ └── package-lock.json
├── variables
│ ├── ViteVariableInterface.php
│ └── ViteVariableTrait.php
├── services
│ ├── VitePluginService.php
│ └── ViteService.php
└── helpers
│ ├── FileHelper.php
│ └── ManifestHelper.php
├── phpstan.neon
├── ecs.php
├── Makefile
├── LICENSE.md
├── composer.json
├── README.md
└── CHANGELOG.md
/src/web/assets/Dockerfile:
--------------------------------------------------------------------------------
1 | ARG TAG=14-alpine
2 | FROM nystudio107/node-dev-base:$TAG
3 |
4 | WORKDIR /app/
5 |
6 | CMD ["run build"]
7 |
8 | ENTRYPOINT ["npm"]
9 |
--------------------------------------------------------------------------------
/phpstan.neon:
--------------------------------------------------------------------------------
1 | includes:
2 | - %currentWorkingDirectory%/vendor/craftcms/phpstan/phpstan.neon
3 |
4 | parameters:
5 | level: 5
6 | paths:
7 | - src
8 |
--------------------------------------------------------------------------------
/src/web/assets/dist/react-refresh-shim.min.js:
--------------------------------------------------------------------------------
1 | import RefreshRuntime from"http://localhost:3000/@react-refresh";RefreshRuntime.injectIntoGlobalHook(window),window.$RefreshReg$=()=>{},window.$RefreshSig$=()=>e=>e,window.__vite_plugin_react_preamble_installed__=!0;
--------------------------------------------------------------------------------
/src/web/assets/src/react-refresh-shim.js:
--------------------------------------------------------------------------------
1 | import RefreshRuntime from 'http://localhost:3000/@react-refresh'
2 | RefreshRuntime.injectIntoGlobalHook(window)
3 | window.$RefreshReg$ = () => {}
4 | window.$RefreshSig$ = () => (type) => type
5 | window.__vite_plugin_react_preamble_installed__ = true
6 |
--------------------------------------------------------------------------------
/ecs.php:
--------------------------------------------------------------------------------
1 | paths([
8 | __DIR__ . '/src',
9 | __FILE__,
10 | ]);
11 | $ecsConfig->parallel();
12 | $ecsConfig->sets([SetList::CRAFT_CMS_4]);
13 | };
14 |
--------------------------------------------------------------------------------
/src/web/assets/dist/safari-nomodule-fix.min.js:
--------------------------------------------------------------------------------
1 | !function(){var e=document.createElement("script");if(!("noModule"in e)&&"onbeforeload"in e){var t=!1;document.addEventListener("beforeload",(function(n){if(n.target===e)t=!0;else if(!n.target.hasAttribute("nomodule")||!t)return;n.preventDefault()}),!0),e.type="module",e.src=".",document.head.appendChild(e),e.remove()}}();
--------------------------------------------------------------------------------
/src/web/assets/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "assets",
3 | "version": "1.0.0",
4 | "description": "",
5 | "scripts": {
6 | "build": "terser src/safari-nomodule-fix.js -c -m -o dist/safari-nomodule-fix.min.js && terser src/react-refresh-shim.js -c -m -o dist/react-refresh-shim.min.js"
7 | },
8 | "keywords": [],
9 | "author": "",
10 | "license": "MIT",
11 | "devDependencies": {
12 | "terser": "^5.7.0"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/web/assets/Makefile:
--------------------------------------------------------------------------------
1 | TAG?=14-alpine
2 | CONTAINER?=craft-plugin-vite-terser
3 | DOCKERRUN=docker container run \
4 | --name ${CONTAINER} \
5 | --rm \
6 | -t \
7 | -v `pwd`:/app \
8 | ${CONTAINER}:${TAG}
9 |
10 | .PHONY: docker build install update npm
11 |
12 | docker:
13 | docker build \
14 | . \
15 | -t ${CONTAINER}:${TAG} \
16 | --build-arg TAG=${TAG} \
17 | --no-cache
18 | build: docker install update
19 | ${DOCKERRUN} \
20 | run build
21 | install: docker
22 | ${DOCKERRUN} \
23 | install
24 | update: docker
25 | ${DOCKERRUN} \
26 | update
27 | npm: docker
28 | ${DOCKERRUN} \
29 | $(filter-out $@,$(MAKECMDGOALS))
30 | %:
31 | @:
32 | # ref: https://stackoverflow.com/questions/6273608/how-to-pass-argument-to-makefile-from-command-line
33 |
--------------------------------------------------------------------------------
/src/web/assets/dist/modulepreload-polyfill.min.js:
--------------------------------------------------------------------------------
1 | !function(){const e=document.createElement("link").relList;if(!(e&&e.supports&&e.supports("modulepreload"))){for(const e of document.querySelectorAll('link[rel="modulepreload"]'))r(e);new MutationObserver((e=>{for(const o of e)if("childList"===o.type)for(const e of o.addedNodes)if("LINK"===e.tagName&&"modulepreload"===e.rel)r(e);else if(e.querySelectorAll)for(const o of e.querySelectorAll("link[rel=modulepreload]"))r(o)})).observe(document,{childList:!0,subtree:!0})}function r(e){if(e.ep)return;e.ep=!0;const r=function(e){const r={};return e.integrity&&(r.integrity=e.integrity),e.referrerpolicy&&(r.referrerPolicy=e.referrerpolicy),"use-credentials"===e.crossorigin?r.credentials="include":"anonymous"===e.crossorigin?r.credentials="omit":r.credentials="same-origin",r}(e);fetch(e.href,r)}}();
--------------------------------------------------------------------------------
/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 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 |
--------------------------------------------------------------------------------
/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-plugin-vite",
3 | "description": "Plugin Vite is the conduit between Craft CMS plugins and Vite, with manifest.json & HMR support",
4 | "version": "5.0.2",
5 | "keywords": [
6 | "craftcms",
7 | "plugin",
8 | "vite"
9 | ],
10 | "support": {
11 | "docs": "https://github.com/nystudio107/craft-plugin-vite/blob/v5/README.md",
12 | "issues": "https://github.com/nystudio107/craft-plugin-vite/issues"
13 | },
14 | "license": "MIT",
15 | "authors": [
16 | {
17 | "name": "nystudio107",
18 | "homepage": "https://nystudio107.com"
19 | }
20 | ],
21 | "minimum-stability": "dev",
22 | "prefer-stable": true,
23 | "require": {
24 | "craftcms/cms": "^5.0.0"
25 | },
26 | "require-dev": {
27 | "craftcms/ecs": "dev-main",
28 | "craftcms/phpstan": "dev-main",
29 | "craftcms/rector": "dev-main"
30 | },
31 | "scripts": {
32 | "phpstan": "phpstan --ansi --memory-limit=1G",
33 | "check-cs": "ecs check --ansi",
34 | "fix-cs": "ecs check --fix --ansi"
35 | },
36 | "config": {
37 | "allow-plugins": {
38 | "craftcms/plugin-installer": true,
39 | "yiisoft/yii2-composer": true
40 | },
41 | "optimize-autoloader": true,
42 | "sort-packages": true
43 | },
44 | "autoload": {
45 | "psr-4": {
46 | "nystudio107\\pluginvite\\": "src/"
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://scrutinizer-ci.com/g/nystudio107/craft-plugin-vite/?branch=v5) [](https://scrutinizer-ci.com/g/nystudio107/craft-plugin-vite/?branch=v5) [](https://scrutinizer-ci.com/g/nystudio107/craft-plugin-vite/build-status/v5) [](https://scrutinizer-ci.com/code-intelligence)
2 |
3 | # Plugin Vite
4 |
5 | Related Articles:
6 |
7 | [Vite.js Next Generation Frontend Tooling + Craft CMS](https://nystudio107.com/blog/using-vite-js-next-generation-frontend-tooling-with-craft-cms)
8 |
9 | [A Vite Buildchain for Craft CMS Plugins](https://nystudio107.com/blog/a-vite-buildchain-for-craft-cms-plugins)
10 |
11 | ## Requirements
12 |
13 | * Craft CMS 5.0.0 or later
14 |
15 | ## Installation
16 |
17 | ```
18 | composer require nystudio107/craft-plugin-vite
19 | ```
20 |
21 | ## Plugin Vite Overview
22 |
23 | Plugin Vite is the conduit between Craft CMS plugins and Vite, with manifest.json & HMR support
24 |
25 | You shouldn't need to install this yourself unless you're using it in a Craft CMS plugin or Module.
26 |
27 | Brought to you by [nystudio107](https://nystudio107.com)
28 |
--------------------------------------------------------------------------------
/src/web/assets/src/safari-nomodule-fix.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * Safari 10.1 supports modules, but does not support the `nomodule` attribute - it will
19 | * load
21 | *
22 | * Again: this will **not** prevent inline script, e.g.:
23 | * .
24 | *
25 | * This workaround is possible because Safari supports the non-standard 'beforeload' event.
26 | * This allows us to trap the module and nomodule load.
27 | *
28 | * Note also that `nomodule` is supported in later versions of Safari - it's just 10.1 that
29 | * omits this attribute.
30 | */
31 | (function() {
32 | var check = document.createElement('script');
33 | if (!('noModule' in check) && 'onbeforeload' in check) {
34 | var support = false;
35 | document.addEventListener('beforeload', function(e) {
36 | if (e.target === check) {
37 | support = true;
38 | } else if (!e.target.hasAttribute('nomodule') || !support) {
39 | return;
40 | }
41 | e.preventDefault();
42 | }, true);
43 |
44 | check.type = 'module';
45 | check.src = '.';
46 | document.head.appendChild(check);
47 | check.remove();
48 | }
49 | }());
50 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Plugin Vite Changelog
2 |
3 | ## 5.0.2 - 2024.08.13
4 | ### Added
5 | * Add a `craft.vite.integrity()` method that will extract the integrity hash (for building a Content Security Policy)
6 | * Added an `includeScriptOnloadHandler` config setting that allows you to disable the adding of an `onload` handler on the `