Closed torbentschechne closed 1 year ago
Update: I needed to use
$basePath = plugin_dir_path( __FILE__);
$manifest = $basePath."/dist/manifest.json";
But the .js is not included on my site. So maybe the hook is the wrong one?
I digged a bit deeper and I have on entry in $entries
in the function add_action
. It's index.js
. But the code as this:
$scriptTag = $this->getScriptTag($entries[0]);
is returning an empty string. When I do this:
add_action('wp_head', function () use ($entries) {
die('test');
foreach ($entries as $entry) {
$scriptTag = $this->getScriptTag($entry);
It's not called.
I got it working when I place the code in the Bootstrap of my plugin. When I use it somewhere where I use another action like this one in my first post it seems that the code from add_action
is not fired properly, because the registration of wp_head does not work. I tried several hooks like plugins_loaded
, admin_init
, wp
none of them work to register the script tag correctly inside wp_head
:/ Any ideas?
I figured it out - I need to use admin_head
as wp_head
is not fired in the backend. So I can not use addAction
, but need to retrieve the script and push it into the head.
I'm very sorry for the late reply, but you caught me at a bad time. Not supporting WordPress plugins has been oversight and I plan to add this in the next release. Thanks for providing your helpful learnings!
@torbentschechne Hopefully, the new version works better for your needs
@idleberg Please can you update your documentatation on how to use this with plugin? I still can't get to import manifest.json when in admin.
First of all, your method inject() in documentation is old and not used anymore. Using addAction in admin does nothing at all.
Hello there,
I just want to use site to bundle my js/node_modules. Then I want to enqueue the built js file in my Wordpress plugin. How can I do this with this package?
I did this:
I did bundle the js file with Vite's Library mode as I do not need a index.html. Now my structure looks like this:
Inside src/dist I have the built js and manifest.json. Now I do this as above, and get
Manifest file does not exist: dist/manifest.json
. This also happens when I do/dist/manifest.json
orsrc/dist/manifest.json
or/src/dist/manifest.json
How does this work with this package? Thanks!