nystudio107 / craft-plugin-vite

Plugin Vite is the conduit between Craft CMS plugins and Vite, with manifest.json & HMR support
MIT License
12 stars 11 forks source link

Resolving issue where assets never served for production builds #5

Closed joepagan closed 2 years ago

joepagan commented 2 years ago

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)
khalwat commented 2 years ago

hrm. At first glance, this does seem to be backward... but as you say, crazy no one has run into this yet. I will look at it futher.

engram-design commented 2 years ago

I'll mention that it's not an issue for me, purely because both values are the same, in most cases:

$path = 'js/main.js'
$manifestKey = 'js/main-legacy.js'

$path = 'js/main-legacy.js'
$manifestKey = 'js/main-legacy.js'

$path = 'js/main.js'
$manifestKey = 'js/main.js'

Might have something to do with my Vite config:

<?php
use craft\helpers\App;

return [
    'useDevServer' => App::env('ENVIRONMENT') === 'local',
    'manifestPath' => '@webroot/dist/manifest.json',
    'devServerPublic' => 'http://localhost:3000/',
    'serverPublic' => rtrim(App::env('BASE_URL'), '/') . '/dist/',
    'errorEntry' => 'js/app.js',
    'cacheKeySuffix' => '',
    'devServerInternal' => 'http://localhost:3000/',
    'checkDevServer' => true,
    'includeReactRefreshShim' => false,
    'criticalPath' => '',
    'criticalSuffix' => '',
];

But otherwise objectively, looks like the comparison isn't correct.

Damn PHP and it's inconsistent function arguments

khalwat commented 2 years ago

Yeah I think my code is wrong, and exactly backward!

khalwat commented 2 years ago

Thank you @joepagan !

joepagan commented 2 years ago

Any time @khalwat feels weird doing something for you for once!