Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare_asset_url can be fooled if the CWD is symlinked to wp-content/plugins #106

Open
lolcabanon opened this issue Sep 6, 2024 · 0 comments

Comments

@lolcabanon
Copy link

Hey! Awesome work here.

I just wanted to raise an issue in case we can improve the code or if someone else faces a similar problem.

I had the issue while using the https://github.com/kucrut/vite-for-wp-example-svelte example, but the issue is related to this repo's code.

So here's the issue I've got :

I have the habit to work in my ~/DEV directory and to symlink relevant folders to the WordPress plugin directory. With npm run dev everything is fine, but with a prod build the URL of the main script is wrongly created.

On this line, since I am working from another directory (ex: /home/USER/DEV/wp-plugin-dev), the $manifest_dir has no overlap with $content_dir so nothing get replaced.

  // vite-for-wp.php
  $url = content_url(str_replace($content_dir, '', $manifest_dir));

The computed URL looks like this : https://wp.dev.local/wp-content/home/USER/DEV/wp-plugin-dev/app/dist but should instead look like this : https://wp.dev.local/wp-content/wp-plugin-dev/app/dist.

Just to be clear, putting the actual root of the project in the WordPress plugins directory, so this issue should not really happen in real productions environments.

How to reproduce

  1. Clone and link the repo
cd ~/DEV # or any folder you want

git clone https://github.com/kucrut/vite-for-wp-example-svelte

ln -s . ~/DEV/dev_wordpress 
  1. composer install && npm install && npm run build
  2. Activate the plugin in WordPress
  3. Look into the Network tab into the inspector => the request for main-XXXXX.js is 404

Hope it's clear enough!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant