Plugin Vite is the conduit between Craft CMS plugins and Vite, with manifest.json & HMR support

Overview
Comments
  • Generate `<link rel=` directives for entry chunks and their direct imports">

    Generate `` directives for entry chunks and their direct imports

    Description

    ViteJS has a feature "Preload Directives Generation" that will automatically generate <link rel="modulepreload"> directives for entry chunks and their direct imports:

    https://vitejs.dev/guide/features.html#preload-directives-generation

    This PR introduces this feature. AsManifestHelper::extractManifestTags() parses the manifest content for the given entry point, it adds a new import type of tag for every file found in the imports key.

    Then every tag of type import is output as <link rel="modulepreload">. It also sets crossorigin to the same value as the given entry point.

    Note: It does not include files found in the dynamicImports key, as the ManifestHelper::extractCssTags() does. I am not certain if this is the right call or not. But it at least is in line with how Vite does it: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/html.ts#L283-L295

    Note 2: Vite appears to have the ability to include a polyfill for the modulepreload tag, which is not included in this PR. https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/modulePreloadPolyfill.ts

    opened by johndwells 26
  • Upgrade to Craft 4 + vite plugin update breaks reload of twig files

    Upgrade to Craft 4 + vite plugin update breaks reload of twig files

    Describe the bug

    In the vite.config.js I have the vite-plugin-restart plugin installed with the following config:

    ViteRestart({
        reload: [
            path.join(__dirname, './templates/**/*'),
        ],
    }),
    

    Previously this worked like a charm but after updating everything to Craft 4 including the vite plugin for Craft this stopped working. The HMR for CSS & JS files are working fine though. Normally you get a notification in the terminal on save saying:

    11:18:34 AM [vite] page reload templates/index.twig
    

    It is now empty or after multiple saves the number of times you saved but doing no reload

    11:18:34 AM [vite] 
    11:18:34 AM [vite] (x2)
    

    sidenote: I'm also noting that after saving the vite.config.js file i'm getting the error:

    client.ts:203          GET http://siteurl.nitro/__vite_ping 404 (Not Found)
    

    To reproduce

    1. nitro ssh
    2. npm run dev
    3. save a twig file from the templates folder

    Expected behaviour

    After hitting save in a .twig file reloading the browser

    Versions

    • Plugin version: 4.0.0-beta.4
    • Craft version: Craft Pro 4.0.1
    • PHP version: 8.0.17
    bug 
    opened by kevinmu17 7
  • Resolving issue where assets never served for production builds

    Resolving issue where assets never served for production builds

    Description

    HUnless I have misunderstood the setup process and some of my settings are incorrect, I believe the strpos values need to be reversed. Hard to believe that nobody has hit this yet, so I suspect I am the problem, if so sorry for the noise...

    When debugging here, my $path never gets beyond this continue.

    image

    strpos(string $haystack, string $needle)
    

    before:

    if (strpos($path, $manifestKey) === false) {
    

    after:

    if (strpos($manifestKey, $path) === false) {
    

    This change does appear to serve the correct assets, though comes with a likely unrelated issue:

    Uncaught SyntaxError: 15
        at Jo (vendor.d63320e8.js:1)
    
    opened by joepagan 5
  • Production build will output no assets

    Production build will output no assets

    opened by watarutmnh 3
  • Configurable `DEVMODE_CACHE_DURATION`

    Configurable `DEVMODE_CACHE_DURATION`

    We've found the 30s cache of DEVMODE_CACHE_DURATION to be pretty slow (and annoying) for local dev via https://github.com/nystudio107/craft-plugin-vite/blob/2f3338d9f60c194e739533efc6bbc3f66e9fdf05/src/helpers/FileHelper.php#L38

    This causes a delay when starting/stopping the dev server due to the cached result for fetching whether the dev server is running or not. Thinking this might be configurable in some fashion?

    opened by engram-design 3
  • Auto reload not happening on twig template changes

    Auto reload not happening on twig template changes

    I've setup a local environment and everything is working as expected except that auto reloading isn't happening whenever twig files are modified. CSS and Javascript files are all loaded with HMR as expected so this is only browser reload. The vite.config.js was pulled straight from your repo (link below).

    https://github.com/nystudio107/craft/blob/craft-vite/buildchain/vite.config.js

    I've attempted to modify the settings passed into VitePlugin, but haven't been able to get it to work.

    Any ideas on what I could start looking at to find the issue?

    Versions

    • Plugin version:1.0.17
    • Craft version:3.6.4
    bug 
    opened by mhill601 2
  • Use `App::env()` to determine value of $useDevServer

    Use `App::env()` to determine value of $useDevServer

    Description

    In our projects we use https://github.com/symfony/dotenv to manage our env vars.

    Symfony Dotenv parses .env files to make environment variables stored in them accessible via $_SERVER or $_ENV.

    By default symfony/dotenv does not use putenv: https://github.com/symfony/dotenv/blob/6.1/Dotenv.php#L59-L70

    App::env() is a little more forgiving. It checks:

    • $_SERVER[$name]
    • getenv($name)
    • defined($name)
    opened by leevigraham 1
  • Consistent use of

    Consistent use of "useDevServer"

    Describe the bug

    The plugin uses two "DEV_MODE" & "VITE_PLUGIN_DEVSERVER" env variables. And not there values but juste the presence of the variable

    Expected behaviour

    It should only take "useDevServer" in config/vite.php

    Versions

    • Plugin version: 1.0.3
    • Craft version: 3.6.12
    bug 
    opened by nicolasbinet 1
  • on demand loading of external files

    on demand loading of external files

    Hi,

    I'm trying to get a setup where i can use the craft.vite.register to only load in an external file (library) when needed, on the whole this is working ok(ish) but i'm running into a few issues i'm hoping you can help with.

    In the vite.config.js file i have this in the build options: rollupOptions: { input: { app: root+'/src/js/app.js', htmx: 'htmx.org', splide: '@splidejs/splide', }, }

    now in a twig partial i add this {{ craft.vite.register("node_modules/htmx.org/dist/htmx.min.js") }} and it works fine both with the devServer and in production.

    First question: I haven't been able to figure out how or if possible to modify the key in the the manifest file to use the value from the rollupOptions above instead of using the full location. So ideally i'll like to use {{ craft.vite.register("htmx.org") }} - if this is not possible to do via vitejs options is it possible to tweak this plugin to allow for partial matches on the manifest keys?

    This also leads onto another issue. When referencing the Splide lib: {{ craft.vite.register("node_modules/@splidejs/splide/dist/js/splide.js") }} this works on the devServer, but not in production. When built the manifest uses the esm version and therefore this full location it not in the manifest file. - This would be solved with the ability to use partial matches.

    Second question: When I update the location to match the one in the manifest file to test it out. The file loads (apparently) but the global object which the lib is providing (Splide) which works in the devServer is not to be found in production. - I know this nothing to do with this plugin, but i hoping you may have come across this issue before and know how to resolved it?

    Thanks

    question 
    opened by samuelbirch 0
Releases(4.0.7)
Owner
nystudio107
Consulting, Branding, Design, Development
nystudio107
Allows the use of the Vite.js next generation frontend tooling with Craft CMS

Vite plugin for Craft CMS 3.x Allows the use of the Vite.js next generation frontend tooling with Craft CMS Related Article: Vite.js Next Generation F

nystudio107 38 Dec 30, 2022
Returns a list of Craft/Vue/React route rules and element URLs for ServiceWorkers from Craft entries

Route Map plugin for Craft CMS 3.x Returns a list of Craft/Vue/React route rules and element URLs for ServiceWorkers from Craft entries Related: Route

nystudio107 30 Mar 14, 2022
Plugin for Craft CMS that makes it easy to interact with the Instagram Basic Display API and Instagram oEmbed.

Instagram Basic Display plugin for Craft CMS 3.x This plugin creates endpoints in your Craft install for you to consume the Instagram Basic Display AP

Jonathan Melville 5 Dec 20, 2022
Provides Twig template IDE autocomplete of Craft CMS & plugin variables

Autocomplete for Craft CMS 3.x Provides Twig template IDE autocompletion for Craft CMS and plugin/module variables and element types. Works with PhpSt

nystudio107 35 Dec 21, 2022
A plugin for Craft CMS 3.X that allows for GraphQL search functionality for matching on fields of nested entries.

Nested Entry GraphQL Plugin This Craft CMS plugin allows for performing graphQL search queries that match on fields on nested entries-as-a-field. What

Rubin EPO 2 Sep 10, 2021
Element Relations Plugin for Craft CMS 3.x

Element Relations Plugin for Craft CMS 3.x This plugin shows all relations of an element. For example, where an asset, entry or any other element is l

Frederic Köberl 2 Jul 18, 2022
Monet Plugin for Craft CMS

A Monet field can be added to asset elements which will generate and store an efficient placeholder image to be displayed inline, whilst the full asset is loading.

Chris Dyer 1 Jan 21, 2022
Craft is a flexible, user-friendly CMS for creating custom digital experiences on the web and beyond.

About Craft CMS Craft is a flexible, user-friendly CMS for creating custom digital experiences on the web and beyond. It features: An intuitive, user-

Craft CMS 2.9k Jan 1, 2023
A BlurHash implementation for Craft CMS.

BlurHash plugin for Craft CMS 3.x Render a BlurHash from a given asset in Craft CMS. A BlurHash is a compact representation of a placeholder for an im

Dodeca Studio 8 Nov 12, 2022
Edit richt text content in Craft CMS using Article by Imperavi.

Article Editor About the plugin This plugin brings the powerful Article Editor from Imperavi to Craft CMS, allowing you to make create beautiful rich

Creativeorange 6 Mar 30, 2022
Provides a twig editor field with Twig & Craft API autocomplete

Twigfield for Craft CMS 3.x & 4.x Provides a twig editor field with Twig & Craft API autocomplete Requirements Twigfield requires Craft CMS 3.0 or 4.0

nystudio107 13 Nov 1, 2022
Baicloud CMS is a lightweight content management system (CMS) based on PHP and MySQL and running on Linux, windows and other platforms

BaiCloud-cms About BaiCloud-cms is a powerful open source CMS that allows you to create professional websites and scalable web applications. Visit the

null 5 Aug 15, 2022
GetSimple CMS - a flatfile CMS that works fast and efficient and has the best UI around, it is written in PHP

GetSimple CMS is a flatfile CMS that works fast and efficient and has the best UI around, it is written in PHP.

null 370 Dec 30, 2022
A Simple and Lightweight WordPress Option Framework for Themes and Plugins

A Simple and Lightweight WordPress Option Framework for Themes and Plugins. Built in Object Oriented Programming paradigm with high number of custom fields and tons of options. Allows you to bring custom admin, metabox, taxonomy and customize settings to all of your pages, posts and categories. It's highly modern and advanced framework.

Codestar 241 Dec 23, 2022
Manage your photos with Piwigo, a full featured open source photo gallery application for the web. Star us on Github! More than 200 plugins and themes available. Join us and contribute!

Manage your photo library. Piwigo is open source photo gallery software for the web. Designed for organisations, teams and individuals. The piwigo.org

Piwigo 2.3k Jan 1, 2023
Flextype is an open-source Hybrid Content Management System with the freedom of a headless CMS and with the full functionality of a traditional CMS

Flextype is an open-source Hybrid Content Management System with the freedom of a headless CMS and with the full functionality of a traditional CMS. Building this Content Management System, we focused on simplicity. To achieve this, we implemented a simple but powerful API's.

Flextype 524 Dec 30, 2022
NukeViet 132 Nov 27, 2022
BaiCloud-cms is a powerful open source CMS that allows you to create professional websites and scalable web applications. Visit the project website for more information.

BaiCloud-cms About BaiCloud-cms is a powerful open source CMS that allows you to create professional websites and scalable web applications. Visit the

null 5 Aug 15, 2022
Bootstrap CMS - PHP CMS powered by Laravel 5 and Sentry

Bootstrap CMS Bootstrap CMS was created by, and is maintained by Graham Campbell, and is a PHP CMS powered by Laravel 5.1 and Sentry. It utilises many

Bootstrap CMS 2.5k Dec 27, 2022