From cb21bb4ad186e8ba3c96b0896e25228450cbb5c4 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Mon, 10 May 2021 14:58:43 -0400 Subject: [PATCH 1/9] Configure docs dir properly --- docs/docs/.vitepress/config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/docs/.vitepress/config.js b/docs/docs/.vitepress/config.js index ba87c89..1704bbf 100644 --- a/docs/docs/.vitepress/config.js +++ b/docs/docs/.vitepress/config.js @@ -5,7 +5,8 @@ module.exports = { lang: 'en-US', themeConfig: { repo: 'nystudio107/craft-vite', - docsDir: 'docs', + docsDir: 'docs/docs', + docsBranch: 'v1', algolia: { apiKey: '', indexName: 'craft-vite' From 68540fbd99ffeca21049e97b1647d326e3c60fe9 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Tue, 11 May 2021 15:49:43 -0400 Subject: [PATCH 2/9] Run on port 3002 --- docs/Makefile | 2 +- docs/docs/vite.config.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 docs/docs/vite.config.js diff --git a/docs/Makefile b/docs/Makefile index 7de266e..4cb77e7 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -3,7 +3,7 @@ CONTAINER?=$(shell basename $(dir $(CURDIR)))-docs DOCKERRUN=docker container run \ --name ${CONTAINER} \ --rm \ - -p 3000:3000 \ + -p 3002:3002 \ -t \ -v `pwd`:/app \ ${CONTAINER}:${TAG} diff --git a/docs/docs/vite.config.js b/docs/docs/vite.config.js new file mode 100644 index 0000000..ae9a578 --- /dev/null +++ b/docs/docs/vite.config.js @@ -0,0 +1,10 @@ +import { defineConfig } from 'vite' + +// https://vitejs.dev/config/ +export default defineConfig({ + server: { + host: '0.0.0.0', + port: 3002, + strictPort: true, + } +}); From 6abbeaa443a519f5fcb81c367d95227f749f187f Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Thu, 13 May 2021 20:53:31 -0400 Subject: [PATCH 3/9] Version 1.0.5 Signed-off-by: Andrew Welch --- CHANGELOG.md | 8 ++++++++ composer.json | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85ac83c..c052bd0 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. +## 1.0.5 - UNRELEASED +### Added +* Moved the live reload through Twig errors to the ViteService so that plugins can get it too + +### Changed +* Use `registerJsFile()` instead of `registerScript()` +* Make the cache last for 30 seconds with `devMode` on + ## 1.0.4 - 2021.05.08 ### Added * Added the `devServerInternal` setting back in, along with `checkDevServer` for people who want the fallback behavior (https://github.com/nystudio107/craft-vite/issues/2) diff --git a/composer.json b/composer.json index 2b56561..82ec76d 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "nystudio107/craft-vite", "description": "Allows the use of the Vite.js next generation frontend tooling with Craft CMS", "type": "craft-plugin", - "version": "1.0.4", + "version": "1.0.5", "keywords": [ "craft", "cms", @@ -23,7 +23,7 @@ ], "require": { "craftcms/cms": "^3.0.0", - "nystudio107/craft-plugin-vite": "^1.0.3" + "nystudio107/craft-plugin-vite": "^1.0.4" }, "autoload": { "psr-4": { From f86992adcc379d0c55a6903965a8ee1dfbdcaaa9 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Thu, 13 May 2021 20:53:49 -0400 Subject: [PATCH 4/9] Moved the live reload through Twig errors to the ViteService so that plugins can get it too Signed-off-by: Andrew Welch --- src/Vite.php | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/src/Vite.php b/src/Vite.php index 029331e..b573264 100755 --- a/src/Vite.php +++ b/src/Vite.php @@ -19,9 +19,7 @@ use craft\base\Plugin; use craft\events\RegisterCacheOptionsEvent; use craft\utilities\ClearCaches; -use craft\web\Application; use craft\web\twig\variables\CraftVariable; -use craft\web\View; use yii\base\Event; @@ -129,13 +127,6 @@ function (RegisterCacheOptionsEvent $event) { ); } ); - // delay attaching event handler to the view component after it is fully configured - $app = Craft::$app; - if ($app->getConfig()->getGeneral()->devMode) { - $app->on(Application::EVENT_BEFORE_REQUEST, function () use ($app) { - $app->getView()->on(View::EVENT_END_BODY, [$this, 'injectErrorEntry']); - }); - } // Log that the plugin has loaded Craft::info( Craft::t( @@ -159,35 +150,6 @@ public function clearAllCaches() // Protected Methods // ========================================================================= - /** - * Inject the error entry point JavaScript for auto-reloading of Twig error - * pages - */ - protected function injectErrorEntry() - { - $response = Craft::$app->getResponse(); - if ($response->isServerError || $response->isClientError) { - $settings = $this->getSettings(); - /** @var Settings $settings */ - if (!empty($settings->errorEntry) && $settings->useDevServer) { - try { - $errorEntry = $settings->errorEntry; - if (is_string($errorEntry)) { - $errorEntry = [$errorEntry]; - } - foreach ($errorEntry as $entry) { - $tag = $this->vite->script($entry); - if ($tag !== null) { - echo $tag; - } - } - } catch (\Throwable $e) { - // That's okay, Vite will have already logged the error - } - } - } - } - /** * Returns the custom Control Panel cache options. * From 015ae6185390143f594837ab34932458213348b1 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Thu, 13 May 2021 21:48:54 -0400 Subject: [PATCH 5/9] Refactored to ViteVariableInterface & ViteVariableTrait Signed-off-by: Andrew Welch --- src/Vite.php | 2 +- src/variables/ViteVariable.php | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100755 src/variables/ViteVariable.php diff --git a/src/Vite.php b/src/Vite.php index b573264..6b7305e 100755 --- a/src/Vite.php +++ b/src/Vite.php @@ -11,9 +11,9 @@ namespace nystudio107\vite; use nystudio107\vite\models\Settings; +use nystudio107\vite\variables\ViteVariable; use nystudio107\pluginvite\services\ViteService; -use nystudio107\pluginvite\variables\ViteVariable; use Craft; use craft\base\Plugin; diff --git a/src/variables/ViteVariable.php b/src/variables/ViteVariable.php new file mode 100755 index 0000000..4d22b00 --- /dev/null +++ b/src/variables/ViteVariable.php @@ -0,0 +1,24 @@ + Date: Thu, 13 May 2021 22:33:52 -0400 Subject: [PATCH 6/9] Version 1.0.5 Signed-off-by: Andrew Welch --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c052bd0..e78ddd3 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. ## 1.0.5 - UNRELEASED ### Added * Moved the live reload through Twig errors to the ViteService so that plugins can get it too +* Added `.fetch()` to allow for fetching of local or remote files, with a caching layer ### Changed * Use `registerJsFile()` instead of `registerScript()` From cfc666baab0c1ab7828f9303abec5b387b02d888 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Fri, 14 May 2021 09:35:49 -0400 Subject: [PATCH 7/9] Version 1.0.5 Signed-off-by: Andrew Welch --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e78ddd3..92d4a10 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. ## 1.0.5 - UNRELEASED ### Added * Moved the live reload through Twig errors to the ViteService so that plugins can get it too -* Added `.fetch()` to allow for fetching of local or remote files, with a caching layer +* Added `.inline()` to allow for inlining of local or remote files in your templates, with a caching layer ### Changed * Use `registerJsFile()` instead of `registerScript()` From 021fac2d9bc29398f1718e77ba48629edc0e5f01 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Fri, 14 May 2021 15:15:19 -0400 Subject: [PATCH 8/9] Added docs for `.inline()` --- docs/docs/index.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/docs/index.md b/docs/docs/index.md index 92d5847..6a5f236 100755 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -291,6 +291,24 @@ This works exactly the way the `.script()` function works, but instead of output This is primarily useful in plugins that must exist inside of the CP, or other things that leverage the Yii2 AssetBundles and dependencies. +### The `.inline()` function + +The Vite plugin also includes a `.inline()` function that inlines the contents of a local file (via path) or remote file (via URL) in your templates. + +Yii2 aliases and/or environment variables may be used, and a caching layer is used so that remote files will be kept in the cache until it is cleared, for performance reasons. + +URL example: + +```twig + {{ craft.vite.inline("https://example.com/my-file.txt") }} +``` + +Path example: + +```twig + {{ craft.vite.inline("@webroot/my-file.txt") }} +``` + ### Other Options The `.script()` and `.register()` functions accept additional options as well: From ca65efca26073feaf2154c5ce0f9350671d93318 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Fri, 14 May 2021 15:15:26 -0400 Subject: [PATCH 9/9] Version 1.0.5 --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92d4a10..f181bb2 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. -## 1.0.5 - UNRELEASED +## 1.0.5 - 2021.05.14 ### Added * Moved the live reload through Twig errors to the ViteService so that plugins can get it too * Added `.inline()` to allow for inlining of local or remote files in your templates, with a caching layer @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. ### Changed * Use `registerJsFile()` instead of `registerScript()` * Make the cache last for 30 seconds with `devMode` on +* Refactored to `ViteVariableInterface` & `ViteVariableTrait` ## 1.0.4 - 2021.05.08 ### Added